Citação de Warren Buffett

Você só descobre quem está nadando pelado quando a maré é baixa.

Warren Buffett

Advertisements

OCI Object Storage Tools

OCI Object Storage Classic Interface Feature Chart

User Story Console API FTM API FTM CLI Java SDK Terraform
Authenticate User Y Y N N N N
Create/Update Bucket Y Y Y N Y Y
List Buckets Y Y Y Y Y N
Delete Bucket Y Y Y Y Y Y
Create/Update Bucket Metadata Y Y Y Y Y N
Retrieve Bucket Metadata Y Y Y Y Y N
Delete Bucket Metadata Y Y Y N Y N
Create/Update Object Y Y Y Y Y Y
List Objects Y Y Y Y Y N
Retrieve Object Y Y Y Y Y N
Delete Object Y Y Y Y Y Y
Create/Update Object Metadata Y Y Y Y Y N
Retrieve Object Metadata Y Y Y Y Y N
Delete Object Metadata Y Y Y N Y N

How to Delete Object Metadata in OCI Object Storage Classic

API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).header("X-Remove-Object-Meta-Sample-Key", "").post(Entity.entity(null, MediaType.WILDCARD_TYPE));

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { 'x-auth-token': ..., 'x-remove-object-meta-sample-key': null }, hostname: 'host', method: 'POST', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject'});

req.end();

API w/ Python

import requests

requests.post('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ..., 'X-Remove-Object-Meta-Sample-Key': None })

API w/ Ruby

require 'rest-client'

RestClient.post 'https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', :x_auth_token => ..., :x_remove_object_meta_sample_key => nil

FTM API

import java.util.HashMap;
import java.util.Map;

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword".toCharArray(), "sampleService", "https://host/", "sampleIdentityDomain"));

    final Map<String, String> metadata = new HashMap<String, String>();

    metadata.put("Sample-Key", null);

    ftm.setObjectMetadata("sampleBucket", "sampleObject", metadata, null);

    ftm.shutdown();
  }

}

FTM CLI

Not supported.

Java SDK

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;

public final class ObjectStorageSample {

  public static void main(final String[] args) throws Exception {
    final CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword".toCharArray()));

    storage.deleteObjectMetadata("sampleBucket", "sampleObject", "Sample-Key"); // omit the "X-Object-Meta" prefix
   }

}

Terraform

N/A.

How to Retrieve Object Metadata in OCI Object Storage Classic

API w/ Java

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).head();

    if (res.getStatus() == 200)
      res.getHeaders().forEach((k, v) -> out.println(k + " = " + v));

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'HEAD', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject'}, (res) => {

  if (res.statusCode === 200)
 
    for (k in res.headers)
      console.log(k + ' = ' + res.headers[k]);

});

req.end();

API w/ Python

import requests

res = requests.head('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... })

if res.ok:
 
  for k, v in res.headers.items():
    print(k + " = " + v)

API w/ Ruby

require 'rest-client'

res = RestClient.head 'https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', :x_auth_token => ...

if res.code == 200
  res.headers.each {|k, v| puts "#{k} = #{v}" }
end

FTM API

import static java.lang.System.out;

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;
import oracle.cloudstorage.ftm.model.CloudObject;
import oracle.cloudstorage.ftm.model.ObjectMetadata;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword".toCharArray(), "sampleService", "https://host/", "sampleIdentityDomain"));

    final CloudObject obj = ftm.getObject("sampleBucket", "sampleObject");

    final ObjectMetadata metadata = obj.getObjectMetadata();

    metadata.getCustomMetadata().forEach((k, v) -> out.println(k + " = " + v));

    ftm.shutdown();
  }

}

FTM CLI

1) Run the following command:

java -jar ftmcli.jar describe -U sampleUser -A https://host/ -S sampleService -I sampleIdentityDomain --save-auth-key sampleBucket sampleObject

Java SDK

import static java.lang.System.out;

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;
import oracle.cloud.storage.model.Key;

public final class ObjectStorageSample {

  public static void main(final String[] args) throws Exception {
    final CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword".toCharArray()));

    final Key obj = storage.describeObject("sampleBucket", "sampleObject");

    obj.getCustomMetadata().forEach((k, v) -> out.println(k + " = " + v));
   }

}

Terraform

N/A.

How to Create/Update Object Metadata in OCI Object Storage Classic

API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).header("X-Object-Meta-Sample-Key", "Sample Value").post(Entity.entity(null, MediaType.WILDCARD_TYPE));

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { 'x-auth-token': ..., 'x-object-meta-sample-key': 'Sample Value' }, hostname: 'host', method: 'POST', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject'});

req.end();

API w/ Python

import requests

requests.post('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ..., 'X-Object-Meta-Sample-Key': 'Sample Value' })

API w/ Ruby

require 'rest-client'

RestClient.post 'https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', '', :x_auth_token => ..., :x_object_meta_sample_key => 'Sample Value'

FTM API

import java.util.HashMap;
import java.util.Map;

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword".toCharArray(), "sampleService", "https://host/", "sampleIdentityDomain"));

    final Map<String, String> metadata = new HashMap<String, String>();

    metadata.put("Sample-Key", "Sample Value");

    ftm.setObjectMetadata("sampleBucket", "sampleObject", metadata, null);

    ftm.shutdown();
  }

}

FTM CLI

1) Run the following command:

java -jar ftmcli.jar set -U sampleUser -A https://host/ -S sampleService -I sampleIdentityDomain --save-auth-key -C "Sample-Key:Sample Value" sampleBucket sampleObject

Java SDK

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;

public final class ObjectStorageSample {

  public static void main(final String[] args) throws Exception {
    final CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword".toCharArray()));

    storage.updateObjectMetadata("sampleBucket", "sampleObject", "Sample-Key", "Sample Value");
  }

}

Terraform

N/A.

How to Delete an Object in OCI Object Storage Classic

API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).delete();

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'DELETE', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject'});

req.end();

API w/ Python

import requests

requests.delete('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... })

API w/ Ruby

require 'rest-client'

RestClient.delete'https://host/v1/sampleService-sampleIdentitYDomain/sampleBucket/sampleObject', :x_auth_token => ...

FTM API

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword".toCharArray(), "sampleService", "https://host/", "sampleIdentityDomain"));

    ftm.delete("sampleBucket", "sampleObject");

    ftm.shutdown();
  }

}

FTM CLI

1) Run the following command:

java -jar ftmcli.jar delete -U sampleUser -A https://host/ -S sampleService -I sampleIdentityDomain --save-auth-key sampleBucket sampleObject

Java SDK

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;

public final class ObjectStorageSample {

  public static void main(final String[] args) throws Exception {
    final CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword".toCharArray()));

    storage.deleteObject("sampleBucket", "sampleObject");
  }

}

Terraform

1) Configure the provider:

export OPC_USERNAME=sampleUser
export OPC_PASSWORD=samplePassword
export OPC_IDENTITY_DOMAIN=sampleIdentityDomain
export OPC_ENDPOINT=https://host/

2) If needed, import the object:

terraform import opc_storage_object.sample_object sampleObject

3) Destroy the object.

How to Retrieve an Object in OCI Object Storage Classic

API w/ Java

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).get();

    if (res.getStatus() == 200)
      out.println(res.readEntity(String.class));

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'GET', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject'}, (res) => {

  if (res.statusCode === 200) {
    var body = '';
 
    res.on('data', (chunk) => {
      body += chunk.toString();
    });
 
    res.on('end', () => {
      console.log(body);
    });
 
  }
 
});
 
req.end();

API w/ Python

import requests

res = requests.get('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... })

if res.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', :x_auth_token => ...

if res.code == 200
  puts res.body
end

FTM API

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword".toCharArray(), "sampleService", "https://host/", "sampleIdentityDomain"));

    ftm.download(null, "sampleBucket", "sampleObject", new File("sampleFile"));

    ftm.shutdown();
  }

}

FTM CLI

1) Run the following command:

java -jar ftmcli.jar download -U sampleUser -A https://host/ -S sampleService -I sampleIdentityDomain -O sampleFile --save-auth-key sampleBucket sampleObject

Java SDK

import static java.lang.System.out;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;
import oracle.cloud.storage.model.StorageInputStream;

public final class ObjectStorageSample {

  public static void main(final String[] args) throws Exception {
    final CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword".toCharArray()));

    final StorageInputStream obj = storage.retrieveObject("sampleBucket", "sampleObject");

    final BufferedReader in = new BufferedReader(new InputStreamReader(obj));

    in.lines().forEach(out::println);
  }

}

Terraform

N/A.

How to List Objects in OCI Object Storage Classic

API w/ Java

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final Client client = ClientBuilder.newClient();

    final Response res = client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket").request(MediaType.WILDCARD_TYPE).header("X-Auth-Token", ...).get();

    if (res.getStatus() == 200)
      out.println(res.readEntity(String.class));

    client.close();
  }

}

API w/ Node.js

const https = require('https');

const req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'GET', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket'}, (res) => {

  if (res.statusCode === 200) {
    var body = '';
 
    res.on('data', (chunk) => {
      body += chunk.toString();
    });
 
    res.on('end', () => {
      console.log(body);
    });
 
  }
 
});
 
req.end();

API w/ Python

import requests

res = requests.get('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket', headers = { 'X-Auth-Token': ... })

if res.ok:
  print(res.text)

API w/ Ruby

require 'rest-client'

res = RestClient.get 'https://host/v1/sampleService-sampleIdentityDomain/sampleBucket', :x_auth_token => ...

if res.code == 200
  puts res.body
end

FTM API

import static java.lang.System.out;

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;

public final class ObjectStorageSample {

  public static void main(final String[] args) {
    final FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword".toCharArray(), "sampleService", "https://host/", "sampleIdentityDomain"));

    ftm.listObjects("sampleBucket").forEach(out::println);

    ftm.shutdown();
  }

}

FTM CLI

1) Run the following command:

java -jar ftmcli.jar list -U sampleUser -A https://host/ -S sampleService -I sampleIdentityDomain --save-auth-key sampleBucket

Java SDK

import static java.lang.System.out;

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;

public final class ObjectStorageSample {

  public static void main(final String[] args) throws Exception {
    final CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword".toCharArray()));

    storage.listObjects("sampleBucket", null).forEach((o) -> out.println(o.getKey()));
  }

}

Terraform

N/A.