• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Node.js SDK)
  4. Lifecycle Management
  5. Viewing Lifecycle Rules

Viewing Lifecycle Rules

You can call ObsClient.getBucketLifecycleConfiguration to view lifecycle rules of a bucket. Sample code is as follows:

// Import the OBS library.
var ObsClient = require('./lib/obs');

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'yourdomainname'
});

obsClient.getBucketLifecycleConfiguration({
       Bucket: 'bucketname'
}, (err, result) => {
       if(err){
              console.log('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
              if(result.CommonMsg.Status < 300 && result.InterfaceResult){
                     for(let i=0;i<result.InterfaceResult.Rules.length;i++){
                           console.log('Rule[' + i + ']:');
                           console.log('ID-->' + result.InterfaceResult.Rules[i]['ID']);
                           console.log('Prefix-->' + result.InterfaceResult.Rules[i]['Prefix']);
                           console.log('Status-->' + result.InterfaceResult.Rules[i]['Status']);
                           for(let j=0;j<result.InterfaceResult.Rules[i]['Transitions'].length;j++){                                   console.log('Transition[' + j + ']:');                                   console.log('Transition[StorageClass]-->' + result.InterfaceResult.Rules[i]['Transitions'][j]['StorageClass']);                                   console.log('Transition[Date]-->' + result.InterfaceResult.Rules[i]['Transitions'][j]['Date']);                                   console.log('Transition[Days]-->' + result.InterfaceResult.Rules[i]['Transitions'][j]['Days']);                            }
                           console.log('Expiration[Date]-->' + result.InterfaceResult.Rules[i]['Expiration']['Date']);
                           console.log('Expiration[Days]-->' + result.InterfaceResult.Rules[i]['Expiration']['Days']);
                           for(let k=0;k<result.InterfaceResult.Rules[i]['NoncurrentVersionTransitions'].length;k++){                                   console.log('NoncurrentVersionTransition[' + k + ']:');                                   console.log('NoncurrentVersionTransition[StorageClass]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionTransitions'][k]['StorageClass']);                                   console.log('NoncurrentVersionTransition[NoncurrentDays]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionTransitions'][k]['NoncurrentDays']);                            }
                           console.log('NoncurrentVersionExpiration[NoncurrentDays]-->' + result.InterfaceResult.Rules[i]['NoncurrentVersionExpiration']['NoncurrentDays']);
                     }
              }
       }
});