Skip to content

Commit 9c2d8f9

Browse files
feat(rust): add env var to control the orchestrator ui url
1 parent d7b2fdd commit 9c2d8f9

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

implementations/rust/ockam/ockam_api/src/orchestrator/space.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::nodes::InMemoryNode;
1313
use crate::orchestrator::email_address::EmailAddress;
1414
use crate::orchestrator::project::models::AdminInfo;
1515
use crate::orchestrator::project::{Project, ProjectsOrchestratorApi};
16-
use crate::orchestrator::subscription::{Subscription, SUBSCRIPTION_PAGE};
16+
use crate::orchestrator::subscription::{subscription_page, Subscription};
1717
use crate::orchestrator::{ControllerClient, HasSecureClient};
1818
use crate::output::{comma_separated, Output};
1919
use crate::terminal::fmt;
@@ -98,7 +98,7 @@ impl Space {
9898
}
9999
if subscription.is_free_trial {
100100
writeln!(f)?;
101-
writeln!(f, "{}", fmt_log!("Please go to {} and subscribe before the trial ends to avoid any service interruptions.", color_uri(SUBSCRIPTION_PAGE)))?;
101+
writeln!(f, "{}", fmt_log!("Please go to {} and subscribe before the trial ends to avoid any service interruptions.", color_uri(subscription_page()?)))?;
102102
writeln!(f, "{}", fmt_log!("{}", color_warn("If you don't subscribe in that time, your Space and all associated Projects will be permanently deleted.")))?;
103103
}
104104
} else {

implementations/rust/ockam/ockam_api/src/orchestrator/subscription.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ use crate::date::UtcDateTime;
33
use crate::orchestrator::{ControllerClient, HasSecureClient};
44
use crate::output::Output;
55
use crate::terminal::fmt;
6+
use crate::{ApiError, ParseError};
67
use colorful::{Colorful, RGB};
78
use miette::IntoDiagnostic;
89
use minicbor::{decode, encode, CborLen, Decode, Decoder, Encode};
910
use ockam::Message;
1011
use ockam_core::api::{Reply, Request};
12+
use ockam_core::env::get_env_with_default;
1113
use ockam_core::{
1214
self, async_trait, cbor_encode_preallocate, Decodable, Encodable, Encoded, Result,
1315
};
@@ -16,10 +18,21 @@ use serde::{Deserialize, Serialize};
1618
use std::fmt::{Display, Formatter, Write};
1719
use std::str::FromStr;
1820
use strum::{Display, EnumString};
21+
use url::Url;
1922

2023
const API_SERVICE: &str = "subscriptions";
2124

22-
pub const SUBSCRIPTION_PAGE: &str = "https://orchestrator.ockam.io";
25+
/// The URL of the Ockam's Orchestrator UI
26+
const OCKAM_ORCHESTRATOR_UI_URL: &str = "OCKAM_ORCHESTRATOR_UI_URL";
27+
const DEFAULT_OCKAM_ORCHESTRATOR_UI_URL: &str = "https://orchestrator.ockam.io/";
28+
29+
pub fn subscription_page() -> crate::Result<Url> {
30+
Url::from_str(&get_env_with_default(
31+
OCKAM_ORCHESTRATOR_UI_URL,
32+
DEFAULT_OCKAM_ORCHESTRATOR_UI_URL.to_string(),
33+
)?)
34+
.map_err(|e| ApiError::Parse(ParseError::Url(e)))
35+
}
2336

2437
#[derive(Encode, Decode, CborLen, Debug, Message)]
2538
#[cfg_attr(test, derive(Clone))]
@@ -451,6 +464,7 @@ pub mod tests {
451464
use super::*;
452465
use crate::schema::tests::validate_with_schema;
453466
use quickcheck::{quickcheck, Arbitrary, Gen, TestResult};
467+
use serial_test::serial;
454468
use std::str::FromStr;
455469

456470
quickcheck! {
@@ -539,4 +553,16 @@ pub mod tests {
539553
assert_eq!(expected.to_string(), to_string);
540554
}
541555
}
556+
557+
#[test]
558+
#[serial]
559+
fn test_orchestrator_url_env() {
560+
std::env::remove_var(OCKAM_ORCHESTRATOR_UI_URL);
561+
let url = subscription_page().unwrap();
562+
assert_eq!(url.as_str(), DEFAULT_OCKAM_ORCHESTRATOR_UI_URL);
563+
564+
std::env::set_var(OCKAM_ORCHESTRATOR_UI_URL, "https://example.com/");
565+
let url = subscription_page().unwrap();
566+
assert_eq!(url.as_str(), "https://example.com/");
567+
}
542568
}

implementations/rust/ockam/ockam_command/src/enroll/command.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use ockam_api::orchestrator::enroll::auth0::*;
3030
use ockam_api::orchestrator::project::Project;
3131
use ockam_api::orchestrator::project::ProjectsOrchestratorApi;
3232
use ockam_api::orchestrator::space::{Space, Spaces};
33-
use ockam_api::orchestrator::subscription::SUBSCRIPTION_PAGE;
33+
use ockam_api::orchestrator::subscription::subscription_page;
3434
use ockam_api::orchestrator::ControllerClient;
3535
use ockam_api::terminal::notification::NotificationHandler;
3636
use ockam_api::{fmt_err, fmt_log, fmt_ok, fmt_warn};
@@ -422,6 +422,8 @@ async fn get_user_space(
422422
node.get_spaces(ctx).await?
423423
};
424424

425+
let subscription_page = subscription_page()?.to_string();
426+
425427
let space = match spaces.first() {
426428
// If the identity has no spaces, create one
427429
None => {
@@ -430,7 +432,7 @@ async fn get_user_space(
430432
.write_line(fmt_log!("No Spaces are accessible to your account.\n"))?;
431433
opts.terminal.write_line(fmt_log!(
432434
"Please go to {} and subscribe to create a new Space.",
433-
color_uri(SUBSCRIPTION_PAGE)
435+
color_uri(&subscription_page)
434436
))?;
435437

436438
if skip_orchestrator_resources_creation {
@@ -453,7 +455,7 @@ async fn get_user_space(
453455
))?;
454456
opts.terminal.write_line(fmt_log!(
455457
"Please go to {} and subscribe to use your Space.",
456-
color_uri(SUBSCRIPTION_PAGE)
458+
color_uri(&subscription_page)
457459
))?;
458460
ask_user_to_subscribe_and_wait_for_space_to_be_ready(opts, ctx, node).await?
459461
}
@@ -467,7 +469,7 @@ async fn get_user_space(
467469
))?;
468470
opts.terminal.write_line(fmt_log!(
469471
"Please go to {} and subscribe to one of our paid plans to use your Space.",
470-
color_uri(SUBSCRIPTION_PAGE)
472+
color_uri(&subscription_page)
471473
))?;
472474
if let Some(grace_period_end_date) = subscription.grace_period_end_date()? {
473475
let date = grace_period_end_date.format_human().into_diagnostic()?;
@@ -493,7 +495,7 @@ async fn get_user_space(
493495
// At this point, the space should have a subscription, but just in case
494496
miette!(
495497
"Please go to {} and try again",
496-
color_uri(SUBSCRIPTION_PAGE)
498+
color_uri(&subscription_page)
497499
)
498500
.wrap_err("The Space does not have a subscription plan attached.")
499501
})?;
@@ -512,12 +514,14 @@ async fn ask_user_to_subscribe_and_wait_for_space_to_be_ready(
512514
ctx: &Context,
513515
node: &InMemoryNode,
514516
) -> Result<Space> {
517+
let subscription_page = subscription_page()?.to_string();
518+
515519
opts.terminal.write_line("")?;
516520
if opts.terminal.can_ask_for_user_input() {
517521
opts.terminal.write(fmt_log!(
518522
"Press {} to open {} in your browser.",
519523
" ENTER ↵ ".bg_white().black().blink(),
520-
color_uri(SUBSCRIPTION_PAGE)
524+
color_uri(&subscription_page)
521525
))?;
522526

523527
let mut input = String::new();
@@ -533,10 +537,10 @@ async fn ask_user_to_subscribe_and_wait_for_space_to_be_ready(
533537
}
534538
}
535539
}
536-
if open::that(SUBSCRIPTION_PAGE).is_err() {
540+
if open::that(&subscription_page).is_err() {
537541
opts.terminal.write_line(fmt_err!(
538542
"Couldn't open your browser from the terminal. Please open {} manually.",
539-
color_uri(SUBSCRIPTION_PAGE)
543+
color_uri(&subscription_page)
540544
))?;
541545
}
542546

implementations/rust/ockam/ockam_command/src/environment/static/env_info.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Devs Usage
6363
- OCKAM_CONTROLLER_ADDR: a `string` that overrides the default address of the controller.
6464
- OCKAM_CONTROLLER_IDENTITY_ID: a `string` that overrides the default identifier of the controller.
6565
- OCKAM_AUTHENTICATOR_ENDPOINT: a `string` that overrides the default endpoint of the authenticator. Defaults to `https://account.ockam.io`.
66+
- OCKAM_ORCHESTRATOR_UI_URL: a `string` that overrides the default URL of the orchestrator UI. Defaults to `https://orchestrator.ockam.io`.
6667
- OCKAM_DEVELOPER: a `boolean` specifying if the current user is an Ockam developer (for more accurate metrics).
6768
- OCKAM_OPENTELEMETRY_EXPORT_DEBUG: a `boolean` specifying if debug messages must be printed to the console when the OpenTelemetry export is configured.
6869
- OCKAM_TELEMETRY_EXPORT_VIA_PROJECT: a `boolean` specifying if traces must be exported via a secure channel to the project node (when it exists)

0 commit comments

Comments
 (0)