Software

How to List Objects in OCI Object Storage Classic

OpenStack Swift 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 class OciClassicSample {

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

    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();
  }

}

OpenStack Swift API w/ Go

package main

import "gopkg.in/resty.v1"

import "fmt"

func main() {
  res, _ := resty.R().SetHeader("X-Auth-Token", ...).Get("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket")

  if res.StatusCode() == 200 {
    fmt.Printf("%v\n", res)
  }

}

OpenStack Swift API w/ Node.js

var https = require('https');

var 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();

OpenStack Swift API w/ Python

import requests

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

if res.ok:
  print res.text

OpenStack Swift 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

OpenStack Swift CLI

1) Configure the CLI:

export ST_AUTH=https://host/auth/v1.0
export ST_USER=sampleservice-sampleidentitydomain:sampleuser
export ST_KEY=samplepassword

2) Run the following command:

swift list samplebucket

OpenStack Swift Client

from swiftclient.service import SwiftService

service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleService-sampleIdentityDomain:sampleUser', 'key': 'samplePassword' })

for res in service.list('sampleBucket'):
  print res

OCI Classic FTM API

import static java.lang.System.out;

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

public class OciClassicSample {

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

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

    ftm.shutdown();
  }

}

OCI Classic 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

OCI Classic Java SDK

import static java.lang.System.out;

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

public class OciClassicSample {

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

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

}

AWS CLI

1) Create the credentials file:

[default]
aws_access_key_id = sampleservice-sampleidentitydomain
aws_secret_access_key = samplesecretaccesskey

2) Run the following command:

aws s3api list-objects --bucket samplebucket --endpoint-url https://host/

Terraform

N/A.

s3cmd

1) Create the .s3cfg file:

[default]
host_base = host
host_bucket = host
access_key = sampleservice-sampleidentitydomain
secret_key = samplesecretaccesskey

2) Run the following command:

s3cmd ls s3://samplebucket

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.