diff --git a/packages/cli/bin.js b/packages/cli/bin.js index 2b5769a35..970eddef0 100755 --- a/packages/cli/bin.js +++ b/packages/cli/bin.js @@ -132,7 +132,30 @@ cli .option('-c, --customer ', 'Billing account email') .option('-na, --no-account', 'Skip account setup') .option('-a, --account ', 'Managing account email') - .action(Space.create) + .option('-ag, --authorize-gateway-services ', 'Authorize Gateways to serve the content uploaded to this space, e.g: \'[{"id":"did:key:z6Mki...","serviceEndpoint":"https://gateway.example.com"}]\'') + .option('-nga, --no-gateway-authorization', 'Skip Gateway Authorization') + .action((name, options) => { + let authorizeGatewayServices = []; + if (options['authorize-gateway-services']) { + try { + authorizeGatewayServices = JSON.parse(options['authorize-gateway-services']); + } catch (err) { + console.error('Invalid JSON format for --authorize-gateway-services'); + process.exit(1); + } + } + + const parsedOptions = { + ...options, + // default to false if not set, so the client will validate the gateway services + skipGatewayAuthorization: options['gateway-authorization'] === false || false, + // default to empty array if not set, so the client will validate the gateway services + authorizeGatewayServices: authorizeGatewayServices || [], + }; + console.log(parsedOptions) + + return Space.create(name, parsedOptions) + }) cli .command('space provision [name]') diff --git a/packages/cli/test/bin.spec.js b/packages/cli/test/bin.spec.js index b09acacc5..2c3b9ccf2 100644 --- a/packages/cli/test/bin.spec.js +++ b/packages/cli/test/bin.spec.js @@ -102,7 +102,7 @@ export const testAccount = { export const testSpace = { 'storacha space create': test(async (assert, context) => { const command = storacha - .args(['space', 'create']) + .args(['space', 'create', '--no-gateway-authorization']) .env(context.env.alice) .fork() @@ -115,7 +115,7 @@ export const testSpace = { 'storacha space create home': test(async (assert, context) => { const create = storacha - .args(['space', 'create', 'home']) + .args(['space', 'create', 'home', '--no-gateway-authorization']) .env(context.env.alice) .fork() @@ -136,7 +136,7 @@ export const testSpace = { 'storacha space create home --no-caution': test(async (assert, context) => { const create = storacha - .args(['space', 'create', 'home', '--no-caution']) + .args(['space', 'create', 'home', '--no-caution', '--no-gateway-authorization']) .env(context.env.alice) .fork() @@ -160,7 +160,7 @@ export const testSpace = { 'storacha space create my-space --no-recovery': test( async (assert, context) => { const create = storacha - .args(['space', 'create', 'home', '--no-recovery']) + .args(['space', 'create', 'home', '--no-recovery', '--no-gateway-authorization']) .env(context.env.alice) .fork() @@ -179,7 +179,7 @@ export const testSpace = { await selectPlan(context) const create = storacha - .args(['space', 'create', 'home', '--no-recovery']) + .args(['space', 'create', 'home', '--no-recovery', '--no-gateway-authorization']) .env(context.env.alice) .fork() @@ -197,7 +197,7 @@ export const testSpace = { await login(context, { email: 'alice@email.me' }) const create = storacha - .args(['space', 'create', 'my-space', '--no-recovery']) + .args(['space', 'create', 'my-space', '--no-recovery', '--no-gateway-authorization']) .env(context.env.alice) .fork() @@ -228,6 +228,7 @@ export const testSpace = { '--customer', 'unknown@web.mail', '--no-account', + '--no-gateway-authorization', ]) .join() .catch() @@ -240,8 +241,6 @@ export const testSpace = { 'storacha space create home --no-recovery --customer alice@web.mail --no-account': test(async (assert, context) => { await login(context, { email: 'alice@web.mail' }) - await login(context, { email: 'alice@email.me' }) - await selectPlan(context) const create = await storacha @@ -250,6 +249,7 @@ export const testSpace = { 'create', 'home', '--no-recovery', + '--no-gateway-authorization', '--customer', 'alice@web.mail', '--no-account', @@ -283,6 +283,7 @@ export const testSpace = { email, '--account', email, + '--no-gateway-authorization', ]) .env(context.env.alice) .join() @@ -312,7 +313,7 @@ export const testSpace = { const { output, error } = await storacha .env(context.env.alice) - .args(['space', 'create', 'home', '--no-recovery']) + .args(['space', 'create', 'home', '--no-recovery', '--no-gateway-authorization']) .join() assert.match(output, /billing account is set/i) @@ -1371,6 +1372,7 @@ export const createSpace = async ( name, '--no-recovery', '--no-account', + '--no-gateway-authorization', ...(customer ? ['--customer', customer] : ['--no-customer']), ]) .env(env)