yakovkhalinsky/backblaze-b2

LIfecicle Rules. How to set them

Closed this issue · 1 comments

Hi there!
Seems that s3 compatible api is the go for tool.
But there are some lifecycle rules that only can be set on the b2 api.
Could someone help me on how to make a createBucket command containing the lifecycle info to set the rules upon creation?
I am trying this below, but the response comes with no lifecycle set.

try {
    await b2.authorize();

    const lifecycleRules = [
      {
        daysFromHidingToDeleting: 35,
        daysFromUploadingToHiding: null,
        fileNamePrefix: 'files/',
      },
    ];
    await b2
      .createBucket({
        bucketName: 'bucketSecretName',
        bucketType: 'allPrivate', // one of `allPublic`, `allPrivate`
        lifecycleRules,
      })
      .then((response) => {
        logger.info(response.data);
      });
  } catch (err) {
    logger.error('Error getting bucket:', err);
  }

And I get this response:

info: {
  accountId: '#########',
  bucketId: '##########',
  bucketInfo: {},
  bucketName: '###########',
  bucketType: 'allPrivate',
  corsRules: [],
  defaultServerSideEncryption: {
    isClientAuthorizedToRead: true,
    value: { algorithm: null, mode: null }
  },
  fileLockConfiguration: {
    isClientAuthorizedToRead: true,
    value: { defaultRetention: [Object], isFileLockEnabled: false }
  },
  lifecycleRules: [],  ==> COMES BLANK
  options: [ 's3' ],
  revision: 2
}

Thanks
Pucci

Looking on the source, seems that this lib does not accept additional parameters to be sent.
So I found another lib to be able to set the lifecycle rules.
if anyone is trying to pragmatically change the lifecycle settings upon bucket creation.
https://github.com/nodecraft/b2-cloud-storage
https://github.com/nodecraft/b2-cloud-storage/blob/main/docs.md#b2CloudStorage+createBucket