/**
 * Copyright (c) 2020, 2021 Oracle and/or its affiliates.  All rights reserved.
 * This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
 */ import common = require ( "oci-common" ) ; import { ObjectStorageClient , requests , models } from "oci-objectstorage" ; const provider = new common . ConfigFileAuthenticationDetailsProvider ( ) ; const args = process . argv . slice ( 2 ) ; if ( args . length !== 4 ) { console . error ( "Unexpected number of arguments received. Please pass absloute directory path to read files from" ) ; process . exit ( - 1 ) ; } const sourceName = args [ 0 ] ; const newName = args [ 1 ] ; const namespaceName = args [ 2 ] ; const bucketName = args [ 3 ] ; const client = new ObjectStorageClient ( { authenticationDetailsProvider : provider } ) ; ( async ( ) => { try { const renameObjectDetails = { sourceName : sourceName , newName : newName } as models . RenameObjectDetails ; const renameObject = { namespaceName : namespaceName , bucketName : bucketName , renameObjectDetails : renameObjectDetails } ; const resp = await client . renameObject ( renameObject ) ; console . log ( resp ) ; console . log ( `Renamed ${ sourceName } to ${ newName }.` ) ; } catch ( ex ) { console . error ( `Failed due to ${ ex }` ) ; console . error ( `The object '${ sourceName }' may not exist in bucket '${ bucketName }' with namespace '${ namespaceName }'` ) ; } } ) ( ) ;