Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: content serve authorization #205

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,29 @@ 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,
// if defined it means we want to skip gateway authorization, so the client will not validate the gateway services
skipGatewayAuthorization: options['gateway-authorization'] === false || options['gateway-authorization'] === undefined,
// default to empty array if not set, so the client will validate the gateway services
authorizeGatewayServices: authorizeGatewayServices || [],
}

return Space.create(name, parsedOptions)
})

cli
.command('space provision [name]')
Expand Down
6 changes: 3 additions & 3 deletions can.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export async function blobAdd(blobPath) {
}

spinner.start('Storing')
const { multihash } = await client.capability.blob.add(blob, {
const { digest } = await client.capability.blob.add(blob, {
receiptsEndpoint: client._receiptsEndpoint.toString()
})
const cid = Link.create(raw.code, multihash)
spinner.stopAndPersist({ symbol: '⁂', text: `Stored ${base58btc.encode(multihash.bytes)} (${cid})` })
const cid = Link.create(raw.code, digest)
spinner.stopAndPersist({ symbol: '⁂', text: `Stored ${base58btc.encode(digest.bytes)} (${cid})` })
}

/**
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export async function authorize(email, opts = {}) {
export async function upload(firstPath, opts) {
/** @type {import('@web3-storage/w3up-client/types').FileLike[]} */
let files
/** @type {number} */
let totalSize // -1 when unknown size (input from stdin)
/** @type {import('ora').Ora} */
let spinner
const client = await getClient()
if (firstPath) {
Expand Down Expand Up @@ -246,7 +248,9 @@ export async function remove(rootCid, opts) {
*/
export async function createSpace(name) {
const client = await getClient()
const space = await client.createSpace(name)
const space = await client.createSpace(name, {
skipGatewayAuthorization: true
})
await client.setCurrentSpace(space.did())
console.log(space.did())
}
Expand Down
Loading
Loading