Skip to content

Commit 0430f2d

Browse files
committed
Parameterize the service URL of the cloud client
This is to allow configuring the service address used, especially in the staging site which now points to the staging service.
1 parent a8ae571 commit 0430f2d

17 files changed

Lines changed: 137 additions & 33 deletions

File tree

.github/workflows/deploy-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v2
28-
- run: ./.github/workflows/publish.sh
28+
- run: ./.github/workflows/publish.sh prod
2929
- uses: JamesIves/github-pages-deploy-action@4.1.4
3030
with:
3131
folder: web/dist

.github/workflows/deploy-staging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
runs-on: ubuntu-latest
2929
steps:
3030
- uses: actions/checkout@v2
31-
- run: ./.github/workflows/publish.sh
31+
- run: ./.github/workflows/publish.sh staging
3232
- uses: JamesIves/github-pages-deploy-action@4.1.4
3333
with:
3434
folder: web/dist

.github/workflows/publish.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
set -eux
1818

19+
node_env="${1}"; shift
20+
1921
curl -o- \
2022
https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
2123

@@ -35,7 +37,7 @@ set -ux
3537

3638
cd web
3739
npm ci --verbose
38-
npm run-script build --verbose
40+
npm run-script "build:${node_env}" --verbose
3941
npm run-script test --verbose
4042
touch dist/.nojekyll
4143
cd -

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
linux-test:
3838
runs-on: ubuntu-latest
3939
env:
40+
SERVICE_URL: "https://service.endbasic.dev/"
4041
TEST_ACCOUNT_1_USERNAME: ${{ secrets.TEST_ACCOUNT_1_USERNAME }}
4142
TEST_ACCOUNT_1_PASSWORD: ${{ secrets.TEST_ACCOUNT_1_PASSWORD }}
4243
TEST_ACCOUNT_2_USERNAME: ${{ secrets.TEST_ACCOUNT_2_USERNAME }}
@@ -51,6 +52,7 @@ jobs:
5152
macos-test:
5253
runs-on: macos-latest
5354
env:
55+
SERVICE_URL: "https://service.endbasic.dev/"
5456
TEST_ACCOUNT_1_USERNAME: ${{ secrets.TEST_ACCOUNT_1_USERNAME }}
5557
TEST_ACCOUNT_1_PASSWORD: ${{ secrets.TEST_ACCOUNT_1_PASSWORD }}
5658
TEST_ACCOUNT_2_USERNAME: ${{ secrets.TEST_ACCOUNT_2_USERNAME }}
@@ -72,6 +74,7 @@ jobs:
7274
windows-test:
7375
runs-on: windows-latest
7476
env:
77+
SERVICE_URL: "https://service.endbasic.dev/"
7578
TEST_ACCOUNT_1_USERNAME: ${{ secrets.TEST_ACCOUNT_1_USERNAME }}
7679
TEST_ACCOUNT_1_PASSWORD: ${{ secrets.TEST_ACCOUNT_1_PASSWORD }}
7780
TEST_ACCOUNT_2_USERNAME: ${{ secrets.TEST_ACCOUNT_2_USERNAME }}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ default:
2727
test-client:
2828
@cd client && \
2929
RUST_BACKTRACE=1 \
30+
SERVICE_URL="$(SERVICE_URL)" \
3031
TEST_ACCOUNT_1_USERNAME="$(TEST_ACCOUNT_1_USERNAME)" \
3132
TEST_ACCOUNT_1_PASSWORD="$(TEST_ACCOUNT_1_PASSWORD)" \
3233
TEST_ACCOUNT_2_USERNAME="$(TEST_ACCOUNT_2_USERNAME)" \

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ for the time being.**
1414

1515
**STILL UNDER DEVELOPMENT; NOT RELEASED YET.**
1616

17+
* Parameterized the cloud service to talk to. In the CLI, the new
18+
`--service-url` allows overriding the default, and in the web, the staging
19+
site now points to the staging service.
20+
1721
* Added a new `endbasic-client` crate to assimilate all of the funcionality
1822
and commands required to talk to the cloud service. This helps to keep the
1923
`endbasic-std` crate leaner dependencies-wise and facilitates configuring

cli/src/main.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,18 @@ fn make_interactive(
123123

124124
/// Completes the build of an interactive machine by taking a partial builder and running post-build
125125
/// steps on it.
126+
///
127+
/// `service_url` is the base URL of the cloud service.
126128
fn finish_interactive_build(
127129
mut builder: endbasic_std::InteractiveMachineBuilder,
130+
service_url: &str,
128131
) -> endbasic_core::exec::Result<endbasic_core::exec::Machine> {
129132
let console = builder.get_console();
130133
let storage = builder.get_storage();
131134

132135
let mut machine = builder.build()?;
133136

134-
let service = Rc::from(RefCell::from(endbasic_client::CloudService::default()));
137+
let service = Rc::from(RefCell::from(endbasic_client::CloudService::new(service_url)?));
135138
endbasic_client::add_all(&mut machine, service, console, storage);
136139

137140
Ok(machine)
@@ -225,9 +228,11 @@ pub fn setup_storage(storage: &mut Storage, local_drive_spec: &str) -> io::Resul
225228
/// Enters the interactive interpreter.
226229
///
227230
/// `local_drive` is the optional local drive to mount and use as the default location.
231+
/// `service_url` is the base URL of the cloud service.
228232
async fn run_repl_loop(
229233
console_spec: Option<&str>,
230234
local_drive_spec: &str,
235+
service_url: &str,
231236
) -> endbasic_core::exec::Result<i32> {
232237
let mut builder = make_interactive(new_machine_builder(console_spec)?);
233238

@@ -237,7 +242,7 @@ async fn run_repl_loop(
237242
let storage = builder.get_storage();
238243
setup_storage(&mut storage.borrow_mut(), local_drive_spec)?;
239244

240-
let mut machine = finish_interactive_build(builder)?;
245+
let mut machine = finish_interactive_build(builder, service_url)?;
241246
endbasic_repl::print_welcome(console.clone())?;
242247
endbasic_repl::try_load_autoexec(&mut machine, console.clone(), storage).await?;
243248
Ok(endbasic_repl::run_repl_loop(&mut machine, console, program).await?)
@@ -256,17 +261,19 @@ async fn run_script<P: AsRef<Path>>(
256261
/// Executes the `path` program in a fresh machine allowing any interactive-only calls.
257262
///
258263
/// `local_drive` is the optional local drive to mount and use as the default location.
264+
/// `service_url` is the base URL of the cloud service.
259265
async fn run_interactive<P: AsRef<Path>>(
260266
path: P,
261267
console_spec: Option<&str>,
262268
local_drive_spec: &str,
269+
service_url: &str,
263270
) -> endbasic_core::exec::Result<i32> {
264271
let mut builder = make_interactive(new_machine_builder(console_spec)?);
265272

266273
let storage = builder.get_storage();
267274
setup_storage(&mut storage.borrow_mut(), local_drive_spec)?;
268275

269-
let mut machine = finish_interactive_build(builder)?;
276+
let mut machine = finish_interactive_build(builder, service_url)?;
270277
let mut input = File::open(path)?;
271278
Ok(machine.exec(&mut input).await?.as_exit_code())
272279
}
@@ -280,6 +287,7 @@ async fn safe_main(name: &str, args: env::Args) -> Result<i32> {
280287
opts.optflag("h", "help", "show command-line usage information and exit");
281288
opts.optflag("i", "interactive", "force interactive mode when running a script");
282289
opts.optopt("", "local-drive", "location of the drive to mount as LOCAL", "URI");
290+
opts.optopt("", "service-url", "base URL of the cloud service", "URL");
283291
opts.optflag("", "version", "show version information and exit");
284292
let matches = opts.parse(args)?;
285293

@@ -295,15 +303,20 @@ async fn safe_main(name: &str, args: env::Args) -> Result<i32> {
295303

296304
let console_spec = matches.opt_str("console");
297305

306+
let service_url = matches
307+
.opt_str("service-url")
308+
.unwrap_or_else(|| endbasic_client::PROD_API_ADDRESS.to_owned());
309+
298310
match matches.free.as_slice() {
299311
[] => {
300312
let local_drive = get_local_drive_spec(matches.opt_str("local-drive"))?;
301-
Ok(run_repl_loop(console_spec.as_deref(), &local_drive).await?)
313+
Ok(run_repl_loop(console_spec.as_deref(), &local_drive, &service_url).await?)
302314
}
303315
[file] => {
304316
if matches.opt_present("interactive") {
305317
let local_drive = get_local_drive_spec(matches.opt_str("local-drive"))?;
306-
Ok(run_interactive(file, console_spec.as_deref(), &local_drive).await?)
318+
Ok(run_interactive(file, console_spec.as_deref(), &local_drive, &service_url)
319+
.await?)
307320
} else {
308321
Ok(run_script(file, console_spec.as_deref()).await?)
309322
}

cli/tests/cli/help.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Options:
77
-i, --interactive force interactive mode when running a script
88
--local-drive URI
99
location of the drive to mount as LOCAL
10+
--service-url URL
11+
base URL of the cloud service
1012
--version show version information and exit
1113

1214
CONSOLE-SPEC can be one of the following:

cli/tests/cli/help.out.sdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Options:
77
-i, --interactive force interactive mode when running a script
88
--local-drive URI
99
location of the drive to mount as LOCAL
10+
--service-url URL
11+
base URL of the cloud service
1012
--version show version information and exit
1113

1214
CONSOLE-SPEC can be one of the following:

client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ bytes = "1.0"
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
2020
time = { version = "0.2", features = ["std"] }
21+
url = "2.2"
2122

2223
[dependencies.endbasic-core]
2324
version = "0.8.99" # ENDBASIC-VERSION

0 commit comments

Comments
 (0)