The documentation of the OpenStack SDK should mention that Swift authentication isn’t supported, but only Keystone v2 and v3.
Tag: OpenStack Swift
Improvement to OpenStack SDK
The documentation of the OpenStack SDK should mention that Swift authentication isn’t supported, but only Keystone v2 and v3.
OpenStack Swift Compatibility Matrix
Use Case | Console | API | CLI | Client | Terraform Provider |
---|---|---|---|---|---|
Generate Authentication Token | Y | Y | Y | Y | N |
Create/Update Bucket | Y | Y | Y | Y | Y |
List Buckets | Y | Y | Y | Y | N |
Delete Bucket | Y | Y | Y | Y | Y |
Create/Update Bucket Metadata | Y | Y | Y | Y | Y |
Retrieve Bucket Metadata | Y | Y | Y | Y | N |
Delete Bucket Metadata | Y | Y | Y | Y | Y |
Create/Update Object | Y | Y | Y | Y | Y |
List Objects | Y | Y | Y | Y | N |
Retrieve Object | Y | Y | Y | Y | N |
Delete Object | Y | Y | Y | Y | Y |
Create/Update Object Metadata | Y | Y | Y | Y | Y |
Retrieve Object Metadata | Y | Y | Y | Y | N |
Delete Object Metadata | Y | Y | Y | Y | Y |
OpenStack Swift Tools
How to Delete Object Metadata in OpenStack Swift
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 class OpenStackSample { public static void main(String[] args) { Client client = ClientBuilder.newClient(); client.target("https://host/v1/sampleAccount/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).header("X-Remove-Object-Meta-Sample-Key", "").post(Entity.entity("", MediaType.WILDCARD_TYPE)); client.close(); } }
API w/ Go
package openstacksample import "gopkg.in/resty.v1" func main() { resty.R().SetHeader("X-Auth-Token", ...).SetHeader("X-Remove-Object-Meta-Sample-Key", "").Post("https://host/v1/sampleAccount/sampleBucket/sampleObject") }
API w/ Node.js
var https = require('https'); var req = https.request({ headers: { 'x-auth-token': ..., 'x-remove-object-meta-sample-key': '' }, hostname: 'host', method: 'POST', path: '/v1/sampleAccount/sampleBucket/sampleObject' }); req.end();
API w/ Python
import requests requests.post('https://host/v1/sampleAccount/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ..., 'X-Remove-Object-Meta-Sample-Key': '' })
API w/ Ruby
require 'rest-client' RestClient.post 'https://Host/v1/sampleAccount/sampleBucket/sampleObject', :x_auth_token => ..., :x_remove_object_meta_sample_key => ''
CLI
1) Configure the CLI:
export ST_AUTH=https://host/auth/v1.0 export ST_USER=sampleuser export ST_KEY=samplepassword
2) Run the following command:
swift post samplebucket sampleobject -H "X-Remove-Object-Meta-Sample-Key:"
Client
from swiftclient.service import SwiftService service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' }) for res in service.post('sampleBucket', [ 'sampleObject' ], { 'header': [ 'X-Remove-Object-Meta-Sample-Key:' ] }): print res
Terraform Provider
1) Configure the provider:
export OS_SWAUTH=true export OS_AUTH_URL=https://host/ export OS_USERNAME=sampleuser export OS_PASSWORD=samplepassword
2) Delete the metadata
values from the object configuration.
3) Apply the change.
How to Retrieve Object Metadata in 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.Response; public class OpenStackSample { public static void main(String[] args) { Client client = ClientBuilder.newClient(); Response res = client.target("https://host/v1/sampleAccount/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/ Go
package openstacksample import "gopkg.in/resty.v1" import "fmt" func main() { res, _ := resty.R().SetHeader("X-Auth-Token", ...).Head("https://host/v1/sampleAccount/sampleBucket/sampleObject") if res.StatusCode() == 200 { for k, v := range res.Header() { fmt.Printf("%v = %v\n", k, v) } } }
API w/ Node.js
var https = require('https'); var req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'HEAD', path: '/v1/sampleAccount/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/sampleAccount/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... }) if res.ok: for k, v in res.headers.items(): print k + ' = ' + v + '\n'
API w/ Ruby
require 'rest-client' res = RestClient.head 'https://Host/v1/sampleAccount/sampleBucket/sampleObject', :x_auth_token => ... if res.code == 200 res.headers.each {|k, v| puts "#{k} = #{v}" } end
CLI
1) Configure the CLI:
export ST_AUTH=https://host/auth/v1.0 export ST_USER=sampleuser export ST_KEY=sampleoassword
2) Run the following command:
swift stat samplebucket sampleobject
Client
from swiftclient.service import SwiftService service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' }) for res in service.stat('sampleBucket', [ 'sampleObject' ]): print res
Terraform Provider
N/A.
How to Create/Update Object Metadata in OpenStack Swift
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 class OpenStackSample { public static void main(String[] args) { Client client = ClientBuilder.newClient(); client.target("https://host/v1/sampleAccount/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).header("X-Object-Meta-Sample-Key", "Sample Value").post(Entity.entity("", MediaType.WILDCARD_TYPE)); client.close(); } }
API w/ Go
package openstacksample import "gopkg.in/resty.v1" func main() { resty.R().SetHeader("X-Auth-Token", ...).SetHeader("X-Object-Meta-Sample-Key", "Sample Value").Post("https://host/v1/sampleAccount/sampleBucket/sampleObject") }
API w/ Node.js
var https = require('https'); var req = https.request({ headers: { 'x-auth-token': ..., 'x-object-meta-sample-key': 'Sample Value' }, hostname: 'host', method: 'POST', path: '/v1/sampleAccount/sampleBucket/sampleObject' }); req.end();
API w/ Python
import requests requests.post('https://host/v1/sampleAccount/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ..., 'X-Object-Meta-Sample-Key': 'Sample Value' })
API w/ Ruby
require 'rest-client' RestClient.post 'https://Host/v1/sampleAccount/sampleBucket/sampleObject', '', :x_auth_token => ..., :x_object_meta_sample_key => 'Sample Value'
CLI
1) Configure the CLI:
export ST_AUTH=https://host/auth/v1.0 export ST_USER=sampleuser export ST_KEY=samplepassword
2) Run the following command:
swift post samplebucket sampleobject -m "Sample-Key:Sample Value
Client
from swiftclient.service import SwiftService service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' }) for res in service.post('sampleBucket', [ 'sampleObject' ], { 'meta': [ 'Sample-Key:Sample Value' ] }): print res
Terraform Provider
1) Configure the provider:
export OS_SWAUTH=true export OS_AUTH_URL=https://host/ export OS_USERNAME=sampleuser export OS_PASSWORD=samplepassword
2) Create the configuration:
resource "openstack_objectstorage_object_v1" "sampleobject" { name = "sampleobject" container_name = "samplebucket" content = sampleFile metadata { Sample-Key = "Sample Value" } }
3) Apply the change.
How to Delete an Object in OpenStack Swift
API w/ Java
import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; public class OpenStackSample { public static void main(String[] args) { Client client = ClientBuilder.newClient(); client.target("https://host/v1/sampleAccount/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).delete(); client.close(); } }
API w/ Go
package openstacksample import "gopkg.in/resty.v1" func main() { resty.R().SetHeader("X-Auth-Token", ...).Delete("https://host/v1/sampleAccount/sampleBucket/sampleObject") }
API w/ Node.js
var https = require('https'); var req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'DELETE', path: '/v1/sampleAccount/sampleBucket/sampleObject' }); req.end();
API w/ Python
import requests requests.delete('https://host/v1/sampleAccount/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... })
API w/ Ruby
require 'rest-client' RestClient.delete 'https://Host/v1/sampleAccount/sampleBucket/sampleObject', :x_auth_token => ...
CLI
1) Configure the CLI:
export ST_AUTH=https://host/auth/v1.0 export ST_USER=sampleUser export ST_KEY=samplePassword
2) Run the following command:
swift delete sampleBucket sampleObject
Client
from swiftclient.service import SwiftService service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' }) for res in service.delete('sampleBucket', [ 'sampleObject' ]): print res
Terraform Provider
1) Configure the provider:
export OS_SWAUTH=true export OS_AUTH_URL=https://host/ export OS_USERNAME=sampleuser export OS_PASSWORD=samplepassword
2) If needed, import the object:
terraform import openstack_objectstorage_container_v1.sampleobject sampleobject
3) Destroy the object.
How to Retrieve an Object in 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.Response; public class OpenStackSample { public static void main(String[] args) { Client client = ClientBuilder.newClient(); Response res = client.target("https://host/v1/sampleAccount/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).get(); if (res.getStatus() == 200) out.println(res.readEntity(String.class)); client.close(); } }
API w/ Go
package openstacksample import "gopkg.in/resty.v1" import "fmt" func main() { res, _ := resty.R().SetHeader("X-Auth-Token", ...).Get("https://host/v1/sampleAccount/sampleBucket/sampleObject") if res.StatusCode() == 200 { fmt.Printf("%v\n", res) } }
API w/ Node.js
var https = require('https'); var req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'GET', path: '/v1/sampleAccount/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/sampleAccount/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... }) if res.ok: print res.text
API w/ Ruby
require 'rest-client' res = RestClient.get 'https://Host/v1/sampleAccount/sampleBucket/sampleObject', :x_auth_token => ... if res.code == 200 puts res.body end
CLI
1) Configure the CLI:
export ST_AUTH=https://host/auth/v1.0 export ST_USER=sampleuser export ST_KEY=samplepassword
2) Run the following command:
swift stat samplebucket sampleobject
Client
from swiftclient.service import SwiftService service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' }) for res in service.stat('sampleBucket', [ 'sampleObject' ]): print res
Terraform Provider
N/A.
How to List Objects in 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 OpenStackSample { public static void main(String[] args) { Client client = ClientBuilder.newClient(); Response res = client.target("https://host/v1/sampleAccount/sampleBucket").request(MediaType.WILDCARD_TYPE).header("X-Auth-Token", ...).get(); if (res.getStatus() == 200) out.println(res.readEntity(String.class)); client.close(); } }
API w/ Go
package openstacksample import "gopkg.in/resty.v1" import "fmt" func main() { res, _ := resty.R().SetHeader("X-Auth-Token", ...).Get("https://host/v1/sampleAccount/sampleBucket") if res.StatusCode() == 200 { fmt.Printf("%v\n", res) } }
API w/ Node.js
var https = require('https'); var req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'GET', path: '/v1/sampleAccount/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/sampleAccount/sampleBucket', headers = { 'X-Auth-Token': ... }) if res.ok: print res.text
API w/ Ruby
require 'rest-client' res = RestClient.get 'https://Host/v1/sampleAccount/sampleBucket', :x_auth_token => ... if res.code == 200 puts res.body end
CLI
1) Configure the CLI:
export ST_AUTH=https://host/auth/v1.0 export ST_USER=sampleuser export ST_KEY=samplepassword
2) Run the following command:
swift list samplebucket
Client
from swiftclient.service import SwiftService service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleUser', 'key': 'samplePassword' }) for res in service.list('sampleBucket'): print res
Terraform Provider
N/A.