Fix credential and credential group not found issue (#567)

* fix credential and group not found issue

* simplify error handling
This commit is contained in:
GokceGK 2024-10-21 15:01:12 +02:00 committed by GitHub
parent 09e2469a79
commit 48d9291329
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package objectstorage
import (
"context"
"fmt"
"net/http"
"strings"
"time"
@ -19,6 +20,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
)
@ -400,6 +402,10 @@ func readCredentials(ctx context.Context, model *Model, client *objectstorage.AP
credentialsGroupResp, err := client.ListAccessKeys(ctx, projectId).CredentialsGroup(credentialsGroupId).Execute()
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if ok && oapiErr.StatusCode == http.StatusNotFound {
return false, nil
}
return false, fmt.Errorf("getting credentials groups: %w", err)
}
if credentialsGroupResp == nil {

View file

@ -3,6 +3,7 @@ package objectstorage
import (
"context"
"fmt"
"net/http"
"strings"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
@ -17,6 +18,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
)
@ -333,6 +335,10 @@ func readCredentialsGroups(ctx context.Context, model *Model, client objectStora
credentialsGroupsResp, err := client.ListCredentialsGroupsExecute(ctx, model.ProjectId.ValueString())
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
if ok && oapiErr.StatusCode == http.StatusNotFound {
return found, nil
}
return found, fmt.Errorf("getting credentials groups: %w", err)
}