Skip to content

Commit

Permalink
fix: Return XAdminMethodNotSupported error for single IAM methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
niksis02 committed Dec 11, 2024
1 parent 0704069 commit 94d23cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions auth/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ func CheckIfAccountsExist(accs []string, iam IAMService) ([]string, error) {
result = append(result, acc)
continue
}
if err == ErrNotSupported {
return nil, s3err.GetAPIError(s3err.ErrNotImplemented)
if errors.Is(err, s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)) {
return nil, err
}
return nil, fmt.Errorf("check user account: %w", err)
}
Expand Down
14 changes: 6 additions & 8 deletions auth/iam_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,37 @@
package auth

import (
"errors"
"github.com/versity/versitygw/s3err"
)

// IAMServiceSingle manages the single tenant (root-only) IAM service
type IAMServiceSingle struct{}

var _ IAMService = &IAMServiceSingle{}

var ErrNotSupported = errors.New("method is not supported")

// CreateAccount not valid in single tenant mode
func (IAMServiceSingle) CreateAccount(account Account) error {
return ErrNotSupported
return s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)
}

// GetUserAccount no accounts in single tenant mode
func (IAMServiceSingle) GetUserAccount(access string) (Account, error) {
return Account{}, ErrNoSuchUser
return Account{}, s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)
}

// UpdateUserAccount no accounts in single tenant mode
func (IAMServiceSingle) UpdateUserAccount(access string, props MutableProps) error {
return ErrNotSupported
return s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)
}

// DeleteUserAccount no accounts in single tenant mode
func (IAMServiceSingle) DeleteUserAccount(access string) error {
return ErrNotSupported
return s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)
}

// ListUserAccounts no accounts in single tenant mode
func (IAMServiceSingle) ListUserAccounts() ([]Account, error) {
return []Account{}, nil
return []Account{}, s3err.GetAPIError(s3err.ErrAdminMethodNotSupported)
}

// Shutdown graceful termination of service
Expand Down
6 changes: 6 additions & 0 deletions s3err/s3err.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const (
ErrAdminUserExists
ErrAdminInvalidUserRole
ErrAdminMissingUserAcess
ErrAdminMethodNotSupported
)

var errorCodeResponse = map[ErrorCode]APIError{
Expand Down Expand Up @@ -636,6 +637,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
Description: "User access key ID is missing.",
HTTPStatusCode: http.StatusNotFound,
},
ErrAdminMethodNotSupported: {
Code: "XAdminMethodNotSupported",
Description: "The method is not supported in single root user mode.",
HTTPStatusCode: http.StatusNotImplemented,
},
}

// GetAPIError provides API Error for input API error code.
Expand Down

0 comments on commit 94d23cc

Please sign in to comment.