update-bucket-status.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { flags } from '@oclif/command'
  2. import { updateStorageBucketStatus } from '../../services/runtime/extrinsics'
  3. import ApiCommandBase from '../../command-base/ApiCommandBase'
  4. import logger from '../../services/logger'
  5. /**
  6. * CLI command:
  7. * Updates the storage bucket status (accept new bags).
  8. *
  9. * @remarks
  10. * Storage working group leader command. Requires storage WG leader priviliges.
  11. * Shell command: "leader:update-bucket-status"
  12. */
  13. export default class LeaderUpdateStorageBucketStatus extends ApiCommandBase {
  14. static description = 'Update storage bucket status (accepting new bags).'
  15. static flags = {
  16. bucketId: flags.integer({
  17. char: 'i',
  18. required: true,
  19. description: 'Storage bucket ID',
  20. }),
  21. set: flags.enum({
  22. char: 's',
  23. description: `Sets 'accepting new bags' parameter for the bucket (on/off).`,
  24. options: ['on', 'off'],
  25. required: true,
  26. }),
  27. ...ApiCommandBase.flags,
  28. }
  29. async run(): Promise<void> {
  30. const { flags } = this.parse(LeaderUpdateStorageBucketStatus)
  31. const bucket = flags.bucketId
  32. // Accept new bags?
  33. const newStatus = flags.set === 'on'
  34. logger.info('Updating the storage bucket status...')
  35. if (flags.dev) {
  36. await this.ensureDevelopmentChain()
  37. }
  38. const account = this.getAccount(flags)
  39. const api = await this.getApi()
  40. const success = await updateStorageBucketStatus(api, account, bucket, newStatus)
  41. this.exitAfterRuntimeCall(success)
  42. }
  43. }