Reference doc : https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm
Based on the reference document, we will go and setup the user to enable API calls.
Navigate to the user profile .
Then navigate to to API keys and click on ADD API keys.
you have multiple options, you can generate your own or you can use oci console to generate one.
I have generated and choosing option 2
tmylaptop /c/tamil/autonomous_learning
$ openssl genrsa -out oci_api_key_150722.pem 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
................................+++++
....................................................................................................................................................................................................................+++++
e is 65537 (0x010001)
tmylaptop /c/tamil/autonomous_learning
$ chmod 700 oci_api_key_150722.pem
tmylaptop /c/tamil/autonomous_learning
$ openssl rsa -pubout -in oci_api_key_150722.pem -out oci_api_key_150722_public.pem
writing RSA key
tmylaptop /c/tamil/autonomous_learning
$ ls -lrt
total 10
-rw-r--r-- 1 tasankar 197121 1831 Jul 16 18:27 oci_api_key
-rw-r--r-- 1 tasankar 197121 404 Jul 16 18:27 oci_api_key.pub
-rw-r--r-- 1 tasankar 197121 1706 Jul 16 18:28 oci_api_key_150722.pem
-rw-r--r-- 1 tasankar 197121 460 Jul 16 18:28 oci_api_key_150722_public.pem
tmylaptop /c/tamil/autonomous_learning
Click Add to add the public key.
Once added , it will give the profile format which you can copy it to use it in the shell to do api calls.
As shown in picture, copy the configure file contents to ~/.oci/config file and update your key file path correctly
Now we will do basic oci rest-api call. to start with just list buckets.
To test this we will use oci raw-request ( this will use api user).
I have configured
API reference
get the api key from : https://docs.oracle.com/en-us/iaas/api/#/en/objectstorage/20160918/
syntax for list from below.
https://docs.oracle.com/en-us/iaas/api/#/en/objectstorage/20160918/Bucket/ListBuckets
oci raw-request --http-method [GET|POST|PUT|DE...] --target-uri https://<respective region service-endpoint>.oraclecloud.com/<<option>>
for list option we need method "GET" and namespace name /n/{namespaceName}/b/"
Will run the following to get the namespace.
oci raw-request --http-method GET --target-uri https://objectstorage.ap-melbourne-1.oraclecloud.com/n/
(ap-melbourne-1)$ oci raw-request --http-method GET --target-uri https://objectstorage.ap-melbourne-1.oraclecloud.com/n/
{
"data": "axatkk9parjt",
"headers": {
"Content-Length": "14",
"Content-Type": "application/json",
"access-control-allow-credentials": "true",
"access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
"access-control-allow-origin": "*",
"access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,date,opc-client-info,opc-request-id,x-api-id",
"date": "Sat, 16 Jul 2022 08:19:27 GMT",
"opc-request-id": "mel-1:a2nRnt0n-IRaSP-dlY6vIO_MjvEupFpQhbnGzBLD0xljTxClTGCfVHt74BlfEQGn",
"x-api-id": "native"
},
"status": "200 OK"
}
Now we will create the syntax to list buckets
oci raw-request --http-method GET --target-uri https://objectstorage.ap-melbourne-1.oraclecloud.com/n/axatkk9parjt/b
(ap-melbourne-1)$ oci raw-request --http-method GET --target-uri https://objectstorage.ap-melbourne-1.oraclecloud.com/n/axatkk9parjt/b
{
"data": {
"code": "MissingCompartmentId",
"message": "The 'compartmentId' query parameter was missing"
},
"headers": {
"Content-Length": "91",
"Content-Type": "application/json",
"access-control-allow-credentials": "true",
"access-control-allow-methods": "POST,PUT,GET,HEAD,DELETE,OPTIONS",
"access-control-allow-origin": "*",
"access-control-expose-headers": "access-control-allow-credentials,access-control-allow-methods,access-control-allow-origin,content-length,content-type,date,opc-client-info,opc-request-id,x-api-id",
"date": "Sat, 16 Jul 2022 08:21:13 GMT",
"opc-request-id": "mel-1:RLqaAJftgZ-IpdfpaHHp-joD7iCTSqVZO5adY7WKpQtooIhJ8bl-fnmPDIYmrFcc",
"x-api-id": "native"
},
"status": "400 Bad Request"
}
I got error and its expected... As per API document reference(https://docs.oracle.com/en-us/iaas/api/#/en/objectstorage/20160918/Bucket/ListBuckets) , we missed to pass the required parameters
Required parameters are : compartment id, namespace.
I tried to pass the parameter as json file but it didn't work. I will update the correct sytnax, once I am successful.
I am able to get the status of the bucket since this request does have mandatory parameter on query part.
Comments
Post a Comment