Object storage misc fixes (#82)
* Fix wrong reference * Fix schema * Fix mapFields not fetching credentials group id * Change expiration timestamp * Fix schema * Remove fields that don't come in the GET response * Add RFC3339SecondsOnly * Change expiration timestamp to not support fractional seconds * Set retry timeout * Harmonize expiration timestamp * Skip import check on credential keys * Add error check * Update docs * Change field description * Add test case, simplify test * Add test case, simplify test * Rename variable * Generate docs --------- Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
This commit is contained in:
parent
5a5ac6640c
commit
248b9834ff
11 changed files with 229 additions and 73 deletions
|
|
@ -10,7 +10,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
|
@ -32,7 +31,7 @@ func (c *objectStorageClientMocked) CreateProjectExecute(_ context.Context, proj
|
|||
}
|
||||
|
||||
func TestMapFields(t *testing.T) {
|
||||
timeValue := time.Now()
|
||||
now := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
description string
|
||||
|
|
@ -51,7 +50,7 @@ func TestMapFields(t *testing.T) {
|
|||
Name: types.StringNull(),
|
||||
AccessKey: types.StringNull(),
|
||||
SecretAccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339Null(),
|
||||
ExpirationTimestamp: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -60,7 +59,7 @@ func TestMapFields(t *testing.T) {
|
|||
&objectstorage.CreateAccessKeyResponse{
|
||||
AccessKey: utils.Ptr("key"),
|
||||
DisplayName: utils.Ptr("name"),
|
||||
Expires: utils.Ptr(timeValue.Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Format(time.RFC3339)),
|
||||
SecretAccessKey: utils.Ptr("secret-key"),
|
||||
},
|
||||
Model{
|
||||
|
|
@ -71,7 +70,7 @@ func TestMapFields(t *testing.T) {
|
|||
Name: types.StringValue("name"),
|
||||
AccessKey: types.StringValue("key"),
|
||||
SecretAccessKey: types.StringValue("secret-key"),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339TimeValue(timeValue),
|
||||
ExpirationTimestamp: types.StringValue(now.Format(time.RFC3339)),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -90,7 +89,23 @@ func TestMapFields(t *testing.T) {
|
|||
Name: types.StringValue(""),
|
||||
AccessKey: types.StringValue(""),
|
||||
SecretAccessKey: types.StringValue(""),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339Null(),
|
||||
ExpirationTimestamp: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"expiration_timestamp_with_fractional_seconds",
|
||||
&objectstorage.CreateAccessKeyResponse{
|
||||
Expires: utils.Ptr(now.Format(time.RFC3339Nano)),
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
Name: types.StringNull(),
|
||||
AccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: types.StringValue(now.Format(time.RFC3339)),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -150,7 +165,7 @@ func TestEnableProject(t *testing.T) {
|
|||
Name: types.StringNull(),
|
||||
AccessKey: types.StringNull(),
|
||||
SecretAccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339Null(),
|
||||
ExpirationTimestamp: types.StringNull(),
|
||||
},
|
||||
false,
|
||||
true,
|
||||
|
|
@ -165,7 +180,7 @@ func TestEnableProject(t *testing.T) {
|
|||
Name: types.StringNull(),
|
||||
AccessKey: types.StringNull(),
|
||||
SecretAccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339Null(),
|
||||
ExpirationTimestamp: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
false,
|
||||
|
|
@ -193,7 +208,7 @@ func TestEnableProject(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestReadCredentials(t *testing.T) {
|
||||
timeValue := time.Now()
|
||||
now := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
description string
|
||||
|
|
@ -225,7 +240,7 @@ func TestReadCredentials(t *testing.T) {
|
|||
Name: types.StringNull(),
|
||||
AccessKey: types.StringNull(),
|
||||
SecretAccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339Null(),
|
||||
ExpirationTimestamp: types.StringNull(),
|
||||
},
|
||||
false,
|
||||
true,
|
||||
|
|
@ -237,17 +252,17 @@ func TestReadCredentials(t *testing.T) {
|
|||
{
|
||||
KeyId: utils.Ptr("foo-cid"),
|
||||
DisplayName: utils.Ptr("foo-name"),
|
||||
Expires: utils.Ptr(timeValue.Add(time.Hour).Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Add(time.Hour).Format(time.RFC3339)),
|
||||
},
|
||||
{
|
||||
KeyId: utils.Ptr("bar-cid"),
|
||||
DisplayName: utils.Ptr("bar-name"),
|
||||
Expires: utils.Ptr(timeValue.Add(time.Minute).Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Add(time.Minute).Format(time.RFC3339)),
|
||||
},
|
||||
{
|
||||
KeyId: utils.Ptr("cid"),
|
||||
DisplayName: utils.Ptr("name"),
|
||||
Expires: utils.Ptr(timeValue.Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Format(time.RFC3339)),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -259,7 +274,41 @@ func TestReadCredentials(t *testing.T) {
|
|||
Name: types.StringValue("name"),
|
||||
AccessKey: types.StringNull(),
|
||||
SecretAccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: timetypes.NewRFC3339TimeValue(timeValue),
|
||||
ExpirationTimestamp: types.StringValue(now.Format(time.RFC3339)),
|
||||
},
|
||||
false,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"expiration_timestamp_with_fractional_seconds",
|
||||
&objectstorage.GetAccessKeysResponse{
|
||||
AccessKeys: &[]objectstorage.AccessKey{
|
||||
{
|
||||
KeyId: utils.Ptr("foo-cid"),
|
||||
DisplayName: utils.Ptr("foo-name"),
|
||||
Expires: utils.Ptr(now.Add(time.Hour).Format(time.RFC3339Nano)),
|
||||
},
|
||||
{
|
||||
KeyId: utils.Ptr("bar-cid"),
|
||||
DisplayName: utils.Ptr("bar-name"),
|
||||
Expires: utils.Ptr(now.Add(time.Minute).Format(time.RFC3339Nano)),
|
||||
},
|
||||
{
|
||||
KeyId: utils.Ptr("cid"),
|
||||
DisplayName: utils.Ptr("name"),
|
||||
Expires: utils.Ptr(now.Format(time.RFC3339Nano)),
|
||||
},
|
||||
},
|
||||
},
|
||||
Model{
|
||||
Id: types.StringValue("pid,cgid,cid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
CredentialsGroupId: types.StringValue("cgid"),
|
||||
CredentialId: types.StringValue("cid"),
|
||||
Name: types.StringValue("name"),
|
||||
AccessKey: types.StringNull(),
|
||||
SecretAccessKey: types.StringNull(),
|
||||
ExpirationTimestamp: types.StringValue(now.Format(time.RFC3339)),
|
||||
},
|
||||
false,
|
||||
true,
|
||||
|
|
@ -287,12 +336,12 @@ func TestReadCredentials(t *testing.T) {
|
|||
{
|
||||
KeyId: utils.Ptr("foo-cid"),
|
||||
DisplayName: utils.Ptr("foo-name"),
|
||||
Expires: utils.Ptr(timeValue.Add(time.Hour).Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Add(time.Hour).Format(time.RFC3339)),
|
||||
},
|
||||
{
|
||||
KeyId: utils.Ptr("bar-cid"),
|
||||
DisplayName: utils.Ptr("bar-name"),
|
||||
Expires: utils.Ptr(timeValue.Add(time.Minute).Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Add(time.Minute).Format(time.RFC3339)),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -307,7 +356,7 @@ func TestReadCredentials(t *testing.T) {
|
|||
{
|
||||
KeyId: utils.Ptr("cid"),
|
||||
DisplayName: utils.Ptr("name"),
|
||||
Expires: utils.Ptr(timeValue.Format(time.RFC3339)),
|
||||
Expires: utils.Ptr(now.Format(time.RFC3339)),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -344,8 +393,9 @@ func TestReadCredentials(t *testing.T) {
|
|||
mockedServer := httptest.NewServer(handler)
|
||||
defer mockedServer.Close()
|
||||
client, err := objectstorage.NewAPIClient(
|
||||
config.WithoutAuthentication(),
|
||||
config.WithEndpoint(mockedServer.URL),
|
||||
config.WithoutAuthentication(),
|
||||
config.WithRetryTimeout(time.Millisecond),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to initialize client: %v", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue