Skip to content

Commit

Permalink
fix(cli): space create
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 12, 2024
1 parent 6f42347 commit 580f93a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
25 changes: 24 additions & 1 deletion packages/cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,30 @@ cli
.option('-c, --customer <email>', 'Billing account email')
.option('-na, --no-account', 'Skip account setup')
.option('-a, --account <email>', 'Managing account email')
.action(Space.create)
.option('-ag, --authorize-gateway-services <json>', '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]')
Expand Down
20 changes: 11 additions & 9 deletions packages/cli/test/bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -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()

Expand All @@ -197,7 +197,7 @@ export const testSpace = {
await login(context, { email: '[email protected]' })

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()

Expand Down Expand Up @@ -228,6 +228,7 @@ export const testSpace = {
'--customer',
'[email protected]',
'--no-account',
'--no-gateway-authorization',
])
.join()
.catch()
Expand All @@ -240,8 +241,6 @@ export const testSpace = {
'storacha space create home --no-recovery --customer [email protected] --no-account':
test(async (assert, context) => {
await login(context, { email: '[email protected]' })
await login(context, { email: '[email protected]' })

await selectPlan(context)

const create = await storacha
Expand All @@ -250,6 +249,7 @@ export const testSpace = {
'create',
'home',
'--no-recovery',
'--no-gateway-authorization',
'--customer',
'[email protected]',
'--no-account',
Expand Down Expand Up @@ -283,6 +283,7 @@ export const testSpace = {
email,
'--account',
email,
'--no-gateway-authorization',
])
.env(context.env.alice)
.join()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1371,6 +1372,7 @@ export const createSpace = async (
name,
'--no-recovery',
'--no-account',
'--no-gateway-authorization',
...(customer ? ['--customer', customer] : ['--no-customer']),
])
.env(env)
Expand Down

0 comments on commit 580f93a

Please sign in to comment.