Skip to content

Commit 41c0b89

Browse files
authored
feat(wasm): add default organization id to run config (#3218)
1 parent 8c22160 commit 41c0b89

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

internal/platform/web/web.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
)
88

99
type Platform struct {
10-
UserAgent string
11-
JWT string
12-
DefaultProjectID string
10+
UserAgent string
11+
JWT string
12+
DefaultProjectID string
13+
DefaultOrganizationID string
1314
}
1415

1516
func (p *Platform) CreateClient(client *http.Client, _ string, _ string) (*scw.Client, error) {
@@ -27,6 +28,10 @@ func (p *Platform) CreateClient(client *http.Client, _ string, _ string) (*scw.C
2728
opts = append(opts, scw.WithDefaultProjectID(p.DefaultProjectID))
2829
}
2930

31+
if p.DefaultOrganizationID != "" {
32+
opts = append(opts, scw.WithDefaultOrganizationID(p.DefaultOrganizationID))
33+
}
34+
3035
return scw.NewClient(opts...)
3136
}
3237

internal/wasm/run.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ func getCommands() *core.Commands {
2121
}
2222

2323
type RunConfig struct {
24-
JWT string `js:"jwt"`
25-
DefaultProjectID string `js:"defaultProjectID"`
24+
JWT string `js:"jwt"`
25+
DefaultProjectID string `js:"defaultProjectID"`
26+
DefaultOrganizationID string `js:"defaultOrganizationID"`
2627
}
2728

2829
type RunResponse struct {
@@ -40,8 +41,9 @@ func runCommand(cfg *RunConfig, args []string, stdout io.Writer, stderr io.Write
4041
Stderr: stderr,
4142
Stdin: nil,
4243
Platform: &web.Platform{
43-
JWT: cfg.JWT,
44-
DefaultProjectID: cfg.DefaultProjectID,
44+
JWT: cfg.JWT,
45+
DefaultProjectID: cfg.DefaultProjectID,
46+
DefaultOrganizationID: cfg.DefaultOrganizationID,
4547
},
4648
})
4749

wasm/cli.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type RunConfig = {
22
jwt: string
33
defaultProjectID: string
4+
defaultOrganizationID: string
45
}
56

67
export type RunResponse = {

wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@scaleway/scaleway-cli-wasm",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "",
55
"type": "module",
66
"main": "index.js",

wasm/src/cli.test.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ import {loadWasmBinary} from "./utils";
1414
const CLI_PACKAGE = 'scw'
1515
const CLI_CALLBACK = 'cliLoaded'
1616

17+
const emptyConfig = (
18+
override?: {
19+
jwt?: string,
20+
defaultProjectID?: string,
21+
defaultOrganizationID?: string
22+
}
23+
): RunConfig => ({
24+
jwt: override?.jwt || "",
25+
defaultProjectID: override?.defaultProjectID || "",
26+
defaultOrganizationID: override?.defaultOrganizationID || "",
27+
})
28+
1729
describe('With wasm CLI', async () => {
1830
let cli: CLI
1931

@@ -24,10 +36,7 @@ describe('With wasm CLI', async () => {
2436

2537
const run = async (expected: string | RegExp, command: string[], runCfg: RunConfig | null = null) => {
2638
if (runCfg === null) {
27-
runCfg = {
28-
jwt: "",
29-
defaultProjectID: ""
30-
}
39+
runCfg = emptyConfig()
3140
}
3241

3342
const resp = await cli.run(runCfg, command)
@@ -37,10 +46,7 @@ describe('With wasm CLI', async () => {
3746

3847
const runWithError = async (expected: string | RegExp, command: string[], runCfg: RunConfig | null = null) => {
3948
if (runCfg === null) {
40-
runCfg = {
41-
jwt: "",
42-
defaultProjectID: "",
43-
}
49+
runCfg = emptyConfig()
4450
}
4551
const resp = await cli.run(runCfg, command)
4652
expect(resp.exitCode).toBeGreaterThan(0)
@@ -49,10 +55,7 @@ describe('With wasm CLI', async () => {
4955

5056
const complete = async (expected: string[], command: string[], runCfg: RunConfig | null = null) => {
5157
if (runCfg === null) {
52-
runCfg = {
53-
jwt: "",
54-
defaultProjectID: ""
55-
}
58+
runCfg = emptyConfig()
5659
}
5760
let toComplete = command.pop() || ""
5861

@@ -74,25 +77,19 @@ describe('With wasm CLI', async () => {
7477
it('can complete', async () => complete(['server', 'image', 'volume'], ['instance', '']))
7578

7679
it('can configure terminal size', async () => {
77-
const runCfg = {
78-
jwt: "",
79-
defaultProjectID: ""
80-
}
80+
const runCfg = emptyConfig()
8181

8282
await cli.configureOutput({width: 100, color: false})
8383
const resp = await cli.run(runCfg, ['marketplace', 'image', 'list'])
84-
console.log(resp)
8584
expect(resp.exitCode).toBe(0)
85+
8686
const lines = resp.stdout.split("\n")
8787
expect(lines.length).toBeGreaterThan(1)
8888
expect(lines[2].length).toBeLessThan(100)
8989
})
9090

9191
it('can enable colors', async () => {
92-
const runCfg = {
93-
jwt: "",
94-
defaultProjectID: ""
95-
}
92+
const runCfg = emptyConfig()
9693

9794
await cli.configureOutput({width: 100, color: false})
9895
const resp = await cli.run(runCfg, ['invalid'])

0 commit comments

Comments
 (0)