Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OBS: Object acl and tests refactor #768

Merged
merged 3 commits into from
Dec 10, 2024
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
92 changes: 92 additions & 0 deletions acceptance/openstack/obs/v1/bucket/obs_acl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package bucket

import (
"os"
"strings"
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/obs"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestObsBucketLifecycleAcl(t *testing.T) {
domainId := os.Getenv("OS_DOMAIN_ID")
if domainId == "" {
t.Skip("OS_DOMAIN_ID is mandatory for this test")
}

client, err := clients.NewOBSClient()
th.AssertNoErr(t, err)

bucketName := strings.ToLower(tools.RandomString("obs-sdk-test", 5))

_, err = client.CreateBucket(&obs.CreateBucketInput{
Bucket: bucketName,
})
t.Cleanup(func() {
_, err = client.DeleteBucket(bucketName)
th.AssertNoErr(t, err)
})
th.AssertNoErr(t, err)

params := &obs.SetBucketAclInput{
Bucket: bucketName,
}

grants := []obs.Grant{
{
Permission: "FULL_CONTROL",
Grantee: obs.Grantee{
ID: domainId,
Type: "CanonicalUser",
},
},
{
Permission: "READ",
Grantee: obs.Grantee{
ID: "1000010021",
Type: "CanonicalUser",
},
},
{
Permission: "READ_ACP",
Grantee: obs.Grantee{
ID: "1000010021",
Type: "CanonicalUser",
},
},
{
Permission: "READ_ACP",
Grantee: obs.Grantee{
ID: "1000010020",
Type: "CanonicalUser",
},
},
{
Permission: "READ",
Grantee: obs.Grantee{
Type: "Group",
URI: "LogDelivery",
},
},
{
Permission: "WRITE",
Grantee: obs.Grantee{
Type: "Group",
URI: "LogDelivery",
},
},
}

params.Owner.ID = domainId
params.Grants = grants

_, err = client.SetBucketAcl(params)
th.AssertNoErr(t, err)

output, err := client.GetBucketAcl(bucketName)
th.AssertNoErr(t, err)
tools.PrintResource(t, output)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1
package bucket

import (
"strings"
Expand All @@ -10,6 +10,37 @@ import (
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestObsBucketLifecycle(t *testing.T) {
client, err := clients.NewOBSClient()
th.AssertNoErr(t, err)

bucketName := strings.ToLower(tools.RandomString("obs-sdk-test", 5))

_, err = client.CreateBucket(&obs.CreateBucketInput{
Bucket: bucketName,
})
t.Cleanup(func() {
_, err = client.DeleteBucket(bucketName)
th.AssertNoErr(t, err)
})
th.AssertNoErr(t, err)

_, err = client.SetBucketEncryption(&obs.SetBucketEncryptionInput{
Bucket: bucketName,
BucketEncryptionConfiguration: obs.BucketEncryptionConfiguration{
SSEAlgorithm: "kms",
},
})
th.AssertNoErr(t, err)

bucketHead, err := client.GetBucketMetadata(&obs.GetBucketMetadataInput{
Bucket: bucketName,
})
th.AssertNoErr(t, err)
th.AssertEquals(t, bucketHead.FSStatus, obs.FSStatusDisabled)
th.AssertEquals(t, bucketHead.Version, "3.0")
}

func TestObsParralelFSBucketLifecycle(t *testing.T) {
client, err := clients.NewOBSClient()
th.AssertNoErr(t, err)
Expand Down
49 changes: 49 additions & 0 deletions acceptance/openstack/obs/v1/bucket/obs_custom_domain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package bucket

import (
"strings"
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/obs"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestOBSCustomDomain(t *testing.T) {
client, err := clients.NewOBSClient()
th.AssertNoErr(t, err)

bucketName := strings.ToLower(tools.RandomString("obs-sdk-test-", 5))

_, err = client.CreateBucket(&obs.CreateBucketInput{
Bucket: bucketName,
})
t.Cleanup(func() {
_, err = client.DeleteBucket(bucketName)
th.AssertNoErr(t, err)
})
th.AssertNoErr(t, err)

domainName := "www.test.com"

input := &obs.SetBucketCustomDomainInput{
Bucket: bucketName,
CustomDomain: domainName,
}
_, err = client.SetBucketCustomDomain(input)
th.AssertNoErr(t, err)

output, err := client.GetBucketCustomDomain(bucketName)
th.AssertNoErr(t, err)

tools.PrintResource(t, output)

inputDelete := &obs.DeleteBucketCustomDomainInput{
Bucket: bucketName,
CustomDomain: domainName,
}

_, err = client.DeleteBucketCustomDomain(inputDelete)
th.AssertNoErr(t, err)
}
73 changes: 73 additions & 0 deletions acceptance/openstack/obs/v1/bucket/obs_inventory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package bucket

import (
"strings"
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/obs"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestOBSInventories(t *testing.T) {
client, err := clients.NewOBSClient()
th.AssertNoErr(t, err)

var (
configId = "test-id"
bucketName = strings.ToLower(tools.RandomString("obs-sdk-test-", 5))
)

_, err = client.CreateBucket(&obs.CreateBucketInput{
Bucket: bucketName,
})
t.Cleanup(func() {
_, err = client.DeleteBucket(bucketName)
th.AssertNoErr(t, err)
})
th.AssertNoErr(t, err)

inventoryOpts := obs.SetBucketInventoryInput{
Bucket: bucketName,
InventoryConfigId: configId,
BucketInventoryConfiguration: obs.BucketInventoryConfiguration{
Id: configId,
IsEnabled: true,
Schedule: obs.InventorySchedule{
Frequency: "Daily",
},
Destination: obs.InventoryDestination{
Format: "CSV",
Bucket: bucketName,
Prefix: "test",
},
Filter: obs.InventoryFilter{
Prefix: "test",
},
IncludedObjectVersions: "All",
OptionalFields: []obs.InventoryOptionalFields{
{
Field: "Size",
},
},
},
}

_, err = client.SetBucketInventory(&inventoryOpts)
th.AssertNoErr(t, err)

getResp, err := client.GetBucketInventory(obs.GetBucketInventoryInput{
BucketName: bucketName,
InventoryConfigId: configId,
})
th.AssertNoErr(t, err)

tools.PrintResource(t, getResp)

_, err = client.DeleteBucketInventory(&obs.DeleteBucketInventoryInput{
Bucket: bucketName,
InventoryConfigId: configId,
})
th.AssertNoErr(t, err)
}
60 changes: 60 additions & 0 deletions acceptance/openstack/obs/v1/bucket/obs_lifecycle_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package bucket

import (
"strings"
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/obs"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

func TestObsBucketLifecycleConfiguration(t *testing.T) {
client, err := clients.NewOBSClient()
th.AssertNoErr(t, err)

bucketName := strings.ToLower(tools.RandomString("obs-sdk-test", 5))

_, err = client.CreateBucket(&obs.CreateBucketInput{
Bucket: bucketName,
})
t.Cleanup(func() {
_, err = client.DeleteBucket(bucketName)
th.AssertNoErr(t, err)
})
th.AssertNoErr(t, err)

_, err = client.SetBucketLifecycleConfiguration(
&obs.SetBucketLifecycleConfigurationInput{
Bucket: bucketName,
BucketLifecycleConfiguration: obs.BucketLifecycleConfiguration{
LifecycleRules: []obs.LifecycleRule{
{
Prefix: "path1/",
Status: "Enabled",
Transitions: []obs.Transition{
{
Days: 30,
StorageClass: "COLD",
},
},
Expiration: obs.Expiration{
Days: 60,
},
},
},
},
},
)
th.AssertNoErr(t, err)

config, err := client.GetBucketLifecycleConfiguration(bucketName)
th.AssertNoErr(t, err)
th.AssertEquals(t, config.BucketLifecycleConfiguration.LifecycleRules[0].Expiration.Days, 60)

t.Cleanup(func() {
_, err := client.DeleteBucketLifecycleConfiguration(bucketName)
th.AssertNoErr(t, err)
})
}
Loading
Loading