Browse Source
refactor: remove configuration.json and migrate Service Accounts to multi-file layout
iam-multi-file-migration
refactor: remove configuration.json and migrate Service Accounts to multi-file layout
iam-multi-file-migration
2 changed files with 131 additions and 63 deletions
-
118weed/credential/filer_etc/filer_etc_identity.go
-
76weed/credential/filer_etc/filer_etc_service_account.go
@ -0,0 +1,76 @@ |
|||
package filer_etc |
|||
|
|||
import ( |
|||
"context" |
|||
"encoding/json" |
|||
"strings" |
|||
|
|||
"github.com/seaweedfs/seaweedfs/weed/filer" |
|||
"github.com/seaweedfs/seaweedfs/weed/glog" |
|||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" |
|||
"github.com/seaweedfs/seaweedfs/weed/pb/iam_pb" |
|||
) |
|||
|
|||
func (store *FilerEtcStore) loadServiceAccountsFromMultiFile(ctx context.Context, s3cfg *iam_pb.S3ApiConfiguration) error { |
|||
return store.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { |
|||
dir := filer.IamConfigDirectory + "/" + IamServiceAccountsDirectory |
|||
entries, err := listEntries(ctx, client, dir) |
|||
if err != nil { |
|||
if err == filer_pb.ErrNotFound { |
|||
return nil |
|||
} |
|||
return err |
|||
} |
|||
|
|||
for _, entry := range entries { |
|||
if entry.IsDirectory { |
|||
continue |
|||
} |
|||
|
|||
var content []byte |
|||
if len(entry.Content) > 0 { |
|||
content = entry.Content |
|||
} else { |
|||
c, err := filer.ReadInsideFiler(client, dir, entry.Name) |
|||
if err != nil { |
|||
glog.Warningf("Failed to read service account file %s: %v", entry.Name, err) |
|||
continue |
|||
} |
|||
content = c |
|||
} |
|||
|
|||
if len(content) > 0 { |
|||
sa := &iam_pb.ServiceAccount{} |
|||
if err := json.Unmarshal(content, sa); err != nil { |
|||
glog.Warningf("Failed to unmarshal service account %s: %v", entry.Name, err) |
|||
continue |
|||
} |
|||
s3cfg.ServiceAccounts = append(s3cfg.ServiceAccounts, sa) |
|||
} |
|||
} |
|||
return nil |
|||
}) |
|||
} |
|||
|
|||
func (store *FilerEtcStore) saveServiceAccount(ctx context.Context, sa *iam_pb.ServiceAccount) error { |
|||
return store.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { |
|||
data, err := json.Marshal(sa) |
|||
if err != nil { |
|||
return err |
|||
} |
|||
return filer.SaveInsideFiler(client, filer.IamConfigDirectory+"/"+IamServiceAccountsDirectory, sa.Id+".json", data) |
|||
}) |
|||
} |
|||
|
|||
func (store *FilerEtcStore) deleteServiceAccount(ctx context.Context, saId string) error { |
|||
return store.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { |
|||
_, err := client.DeleteEntry(ctx, &filer_pb.DeleteEntryRequest{ |
|||
Directory: filer.IamConfigDirectory + "/" + IamServiceAccountsDirectory, |
|||
Name: saId + ".json", |
|||
}) |
|||
if err != nil && !strings.Contains(err.Error(), filer_pb.ErrNotFound.Error()) { |
|||
return err |
|||
} |
|||
return nil |
|||
}) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue