1

do you have any idea or link resources on how to configure swift to allow cors. Currrently im doing javascript upload function in openstack swift but im getting an error "No Access-Control-Allow-Origin". Thanks

darrel
  • 51
  • 5
  • https://www.google.com/search?q=openstack+swift+cors the first four links look interesting – Anshu Prateek May 27 '15 at 09:54
  • @Anshu Prateek i already see that and try but still no luck. Maybe it needs some openstack server configuration, but we have no idea. – darrel May 27 '15 at 10:00
  • Possible duplicate of [CORS support in OpenStack SWIFT](https://stackoverflow.com/questions/29041346/cors-support-in-openstack-swift) – Felipe Sep 15 '17 at 12:43

2 Answers2

0

Maybe you are trying to reach a container that you did not append the origin of the page to the container’s X-Container-Meta-Access-Control-Allow-Origin header. You can append it to your container using something like this curl:

curl -X POST -H 'X-Auth-Token: xxx' \
  -H 'X-Container-Meta-Access-Control-Allow-Origin: http://localhost' \
  http://192.168.56.3:8080/v1/AUTH_test/cont1

Here is the full description on this subject on Openstack documentation: http://docs.openstack.org/developer/swift/cors.html

0

For anyone that went to the official docs and then was stuck with the paramentes for the cURL post.

This are two ways of doing this.

Using python-openstackclient

Use pip install python-openstackclient to get the package and use the ENV vars to authenticate.

Once you can issue a command like openstack container show your-container, then you can also use set --property.

E.g

openstack container set --property Access-Control-Allow-Headers='Content-Type, X-CSRFToken' your-container
openstack container set --property Access-Control-Allow-Origin='https://your.domain.com https://other.domain.com' your-container

Using cURL

In order to user curl, you want to post a command like:

curl -i -X POST -H 'X-Auth-Token: <YOUR_TOKEN>' \
  -H 'X-Container-Meta-Access-Control-Allow-Origin: https://your.domain.com ' \
  <YOUR_STORAGE_URL/your-container>

For this you need to find YOUR_TOKEN and YOUR_STORAGE_URL.

You can use the python-swiftclient (pip install python-swiftclient). After authenticating, run

swift stat -v --info

The output will contain both:

                 StorageURL: YOUR_STORAGE_URL
                 Auth Token: YOUR_TOKEN
                    Account: v1
                 Containers: 99
                    Objects: 9999
                      Bytes: 999999
  Strict-Transport-Security: max-age=31536000; includeSubdomains
                     Server: nginx
                 Connection: keep-alive
                X-Timestamp: 1505478377.08455
X-Account-Bytes-Used-Actual: 9999999
                 X-Trans-Id: tx009999999999a9-999999-9999999-default
               Content-Type: text/plain; charset=utf-8
              Accept-Ranges: bytes
Felipe
  • 440
  • 3
  • 18