Creating mini PHP SDK to sign Oracle Cloud Infrastructure API requests

Alexander Hitrov
6 min readFeb 11, 2021

Idea to create such library came into my mind when I wanted to start using all the free benefits that Oracle Cloud Infrastructure provides. Specifically I am talking about 10 GB of Object Storage as well as 10 TB of outgoind traffic. Its has significant differences with expensive AWS S3. Unfortunately, Oracle Cloud does not have (yet?) the SDK for the most popular programming language for developing websites. Good news is that it’s partially compatible with Amazon S3 — meaning that tools that we already have could be applied, including it’s PHP SDK.

Those who can’t wait to see the code, please welcome https://github.com/hitrov/oci-api-php-request-sign

Current tools allow us to perform almost all operations that we could imagine for creating, reading and deleting buckets and objects (files). Buckets can be public (with or without files listing possibility) or private. There’s also an option to upload files having only “secret” URL (generated through CLI or web interface — Oracle Cloud Console). In fact, this should already cover a lot of scenarios especially if you generate brute-force filenames in case you don’t want to expose files to everyone.

I was particularly interested in “sharing” files possibility — to have public links as well as to limit (“unshare”) if needed. In case if there’re not a lot of them you can do it manually. But we are all here to have programmatic access. In AWS S3 it’s called Pre-Signed URL. Oracle Cloud has the name Pre-Authenticated Request.

Install AWS PHP SDK

composer require aws/aws-sdk-php

Please refer below to generate OCI credentials for AWS PHP SDK.

Here’s where you can see your namespace

require('vendor/autoload.php');$namespaceName = 'frpegp***';
$bucketName = 'test******05';
$region = 'eu-frankfurt-1';
$endpoint = "https://$namespaceName.compat.objectstorage.$region.oraclecloud.com";
$s3 = new Aws\S3\S3Client([
'version' => 'latest',
'region' => $region…

--

--