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

fix: move auth internal UserAcc to auth.Account #210

Merged
merged 1 commit into from
Sep 6, 2023
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
3 changes: 2 additions & 1 deletion auth/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

// Account is a gateway IAM account
type Account struct {
Access string `json:"access"`
Secret string `json:"secret"`
Role string `json:"role"`
}
Expand All @@ -31,7 +32,7 @@ type IAMService interface {
CreateAccount(access string, account Account) error
GetUserAccount(access string) (Account, error)
DeleteUserAccount(access string) error
ListUserAccounts() ([]UserAcc, error)
ListUserAccounts() ([]Account, error)
}

var ErrNoSuchUser = errors.New("user not found")
14 changes: 4 additions & 10 deletions auth/iam_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ type Storer interface {
StoreIAM(UpdateAcctFunc) error
}

type UserAcc struct {
Access string `json:"access"`
Secret string `json:"secret"`
Role string `json:"role"`
}

// IAMConfig stores all internal IAM accounts
type IAMConfig struct {
AccessAccounts map[string]Account `json:"accessAccounts"`
Expand Down Expand Up @@ -187,13 +181,13 @@ func (s *IAMServiceInternal) DeleteUserAccount(access string) error {
}

// ListUserAccounts lists all the user accounts stored.
func (s *IAMServiceInternal) ListUserAccounts() (accs []UserAcc, err error) {
func (s *IAMServiceInternal) ListUserAccounts() (accs []Account, err error) {
s.mu.RLock()
defer s.mu.RUnlock()

data, err := s.storer.GetIAM()
if err != nil {
return []UserAcc{}, fmt.Errorf("get iam data: %w", err)
return []Account{}, fmt.Errorf("get iam data: %w", err)
}

serial := crc32.ChecksumIEEE(data)
Expand All @@ -202,12 +196,12 @@ func (s *IAMServiceInternal) ListUserAccounts() (accs []UserAcc, err error) {
err := s.updateCache()
s.mu.RLock()
if err != nil {
return []UserAcc{}, fmt.Errorf("refresh iam cache: %w", err)
return []Account{}, fmt.Errorf("refresh iam cache: %w", err)
}
}

for access, usr := range s.accts.AccessAccounts {
accs = append(accs, UserAcc{
accs = append(accs, Account{
Access: access,
Secret: usr.Secret,
Role: usr.Role,
Expand Down
2 changes: 1 addition & 1 deletion cmd/versitygw/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func listUsers(ctx *cli.Context) error {
}
defer resp.Body.Close()

var accs []auth.UserAcc
var accs []auth.Account
if err := json.Unmarshal(body, &accs); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions s3api/controllers/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ func TestAdminController_ListUsers(t *testing.T) {

adminController := AdminController{
IAMService: &IAMServiceMock{
ListUserAccountsFunc: func() ([]auth.UserAcc, error) {
return []auth.UserAcc{}, nil
ListUserAccountsFunc: func() ([]auth.Account, error) {
return []auth.Account{}, nil
},
},
}

adminControllerErr := AdminController{
IAMService: &IAMServiceMock{
ListUserAccountsFunc: func() ([]auth.UserAcc, error) {
return []auth.UserAcc{}, fmt.Errorf("server error")
ListUserAccountsFunc: func() ([]auth.Account, error) {
return []auth.Account{}, fmt.Errorf("server error")
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions s3api/controllers/iam_moq_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.