Question
· Jun 30, 2020

Iris & Buckets

Hi, someone have connected Iris to a Bucket ? like aws, huawei, etc.

I try to use private Bucket as storage for files, and Iris as database & API interface to manage this files, but al SDKs are in another languages, no one have founded on COS.

I have tested some examples, but with bad results

Set request = ##class(%Net.HttpRequest).%New()
Set request.Server = "..."
Set request.Port = "443"
Set request.Https = $$$YES
Set request.SSLConfiguration="default"
Set request.Date = $zdt($h,2)
Set AccessKeyID = "..."
Set ExpiresValue = $ZDATETIME($HOROLOG,-2)+60
Set StringToSign =
                         "GET" _ "\n" _
                         "" _ "\n" _
                         "text/plain" _ "\n" _
                        ExpiresValue _ "\n"
Set signature =
                    $zconvert($system.Encryption.Base64Encode($system.Encryption.HMACSHA1(StringToSign,"...")),"O","URL")
Set tURL = "/ObjectKey?AccessKeyId="_ AccessKeyID _   "&Expires="_ ExpiresValue _  "&Signature="_ signature
Do request.Get("/files/" _ tFind _ ".ext")

And a have a 403 Error  (is not the first test ... )

Discussion (3)0
Log in or sign up to continue

While the idea is essentially the same (REST API) - each cloud provider uses slightly different calls and signatures to access data in the storage bucket. So unlikely you'll find a single example that works for every provider.

IRIS External Table  contains Object Script implementation of the storage bucket adapters for AWS, Azure and Google Cloud.

https://github.com/intersystems-community/IRIS-ExternalTable#using-cloud-adapters-outside-of-externaltable - would give you an idea on how to use adapters directly.
 

in my case, some fixes for Huawei (like Old version s3)

Class Cloud.Storage
{
ClassMethod GetOBSCredentials(profile = "CloudStorage") As %Status
{
    Set tUsername = ##Class(Ens.Config.Credentials).%OpenId(profile)
    If (tUsername){
        Set %extOBS("AccessKeyId")=tUsername.Username
        Set %extOBS("SecretAccessKey")=tUsername.Password
    }
    Quit $$$OK
}
ClassMethod OBSSignRequest(ByRef request, requeststring, bucket) As %String
{
    If '$data(%extOBS) {
        Set sc=..GetOBSCredentials()
    }
    Set tAccessKeyId = %extOBS("AccessKeyId")
    Set tSecretAccessKey = %extOBS("SecretAccessKey")
    Set tDateH = $ZTS
    Set tWeekDay = $Piece($ZDateTime(tDateH,11)," ",1)
    Set tDate = tWeekDay_", "_$ZDateTime(tDateH,2,1)_" GMT"
    Set request.Date = tDate
    Set tContentMD5 = ""
    Set tContentType = ""
    Set CanonicalizedHeaders = "x-obs-acl:private"
    Set tStringToSign = $Piece(requeststring," ",1)_$Char(10)_
                            tContentMD5_$Char(10)_
                            tContentType_$Char(10)_
                            tDate_$Char(10)_
                            "/"_ bucket_$Piece(requeststring," ",2)
    Set tStringToSignUTF8 = $Zconvert(tStringToSign,"O","UTF8")
    Set tSignature = ##Class(%SYSTEM.Encryption).HMACSHA1(tStringToSignUTF8,tSecretAccessKey)
    Set tSignatureBase64 = ##Class(%SYSTEM.Encryption).Base64Encode(tSignature)
    Set tAuthorization = "OBS "_tAccessKeyId_":"_tSignatureBase64
    Set request.Authorization=tAuthorization
    Quit $$$OK
}
ClassMethod GetFileHeader(filename, ByRef stream As %Stream.GlobalBinary, ByRef status As %Library.DynamicObject, classname = "") As %Status
{
    Set status = {}
    Set bucket = $Piece(filename,"/",3)
    Set key=$Piece(filename,"/",4,*)
    Set object="/"_bucket_"/"_key
    Set obsRegion=$Get(^EXT.OBSBucketRegion(bucket),"la-south-2")
    Set server = bucket_".obs."_obsRegion_".myhuaweicloud.com"
    Set request = ##Class(%Net.HttpRequest).%New()
    Set request.Server = server
    Set request.Https=1
    Set request.SSLConfiguration="ISC.FeatureTracker.SSL.Config"
    Set url =  "/"_key
    Set requeststring="GET "_"/"_key
    Set sc= ..OBSSignRequest(request,requeststring,bucket)
    Set sc = request.Get(url)
    Set status.code = request.HttpResponse.StatusCode
    Set stream=request.HttpResponse.Data
    Set stream.LineTerminator=$Char(10)
    Quit $$$OK
}
}

I use Credentials to save data.

Thanks !!