Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ func NewOCI(conf *OCIConfig) (Storage, error) {
client.HTTPClient = c
}

// The SDK only prepends a scheme to client.Host on the first request, so
// read it before GetNamespace below.
host := strings.TrimPrefix(client.Host, "https://")
// client.Host keeps endpoint options such as {dualStack?ds.oci.:}, which the
// SDK resolves on a copy per request, so resolve them the same way here.
resolved := client.BaseClient
common.UpdateEndpointTemplateForOptions(&resolved)
host := strings.TrimPrefix(resolved.Host, "https://")
insecure := strings.HasPrefix(host, "http://")
host = strings.TrimPrefix(host, "http://")

Expand Down
27 changes: 27 additions & 0 deletions oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
package storage

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"net/url"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -63,3 +68,25 @@ func TestNewConfigProvider(t *testing.T) {
require.NotNil(t, provider)
})
}

func TestOCILocationHost(t *testing.T) {
key, err := rsa.GenerateKey(rand.Reader, 2048)
require.NoError(t, err)
pemKey := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(key)})

// A set Namespace keeps NewOCI off the network.
s, err := NewOCI(&OCIConfig{
TenancyOCID: "ocid1.tenancy.oc1..tenancy",
UserOCID: "ocid1.user.oc1..user",
Fingerprint: "aa:bb:cc",
PrivateKey: string(pemKey),
Region: "us-chicago-1",
Namespace: "ns",
Bucket: "bucket",
})
require.NoError(t, err)

u, err := url.Parse(s.(*ociStorage).location("a/b.mp4"))
require.NoError(t, err)
require.Equal(t, "objectstorage.us-chicago-1.oraclecloud.com", u.Host)
}
Loading