mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
use entry content filed
This commit is contained in:
parent
03620776ec
commit
a3d4b50a49
|
@ -33,7 +33,7 @@ func (ifs *IAMFilerStore) LoadIAMConfig(config *iam_pb.S3ApiConfiguration) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ifs.loadIAMConfigFromEntryExtended(&resp.Entry.Extended, config)
|
err = ifs.loadIAMConfigFromEntry(resp.Entry.Content, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -51,14 +51,12 @@ func (ifs *IAMFilerStore) SaveIAMConfig(config *iam_pb.S3ApiConfiguration) error
|
||||||
Collection: "",
|
Collection: "",
|
||||||
Replication: "",
|
Replication: "",
|
||||||
},
|
},
|
||||||
Extended: make(map[string][]byte),
|
Content: []byte{},
|
||||||
}
|
}
|
||||||
|
err := ifs.saveIAMConfigToEntry(entry.Content, config)
|
||||||
err := ifs.saveIAMConfigToEntryExtended(&entry.Extended, config)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = filer_pb.LookupEntry(*ifs.client, ifs.getIAMConfigRequest())
|
_, err = filer_pb.LookupEntry(*ifs.client, ifs.getIAMConfigRequest())
|
||||||
if err == filer_pb.ErrNotFound {
|
if err == filer_pb.ErrNotFound {
|
||||||
err = filer_pb.CreateEntry(*ifs.client, &filer_pb.CreateEntryRequest{
|
err = filer_pb.CreateEntry(*ifs.client, &filer_pb.CreateEntryRequest{
|
||||||
|
@ -81,24 +79,17 @@ func (ifs *IAMFilerStore) SaveIAMConfig(config *iam_pb.S3ApiConfiguration) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ifs *IAMFilerStore) loadIAMConfigFromEntryExtended(extended *map[string][]byte, config *iam_pb.S3ApiConfiguration) error {
|
func (ifs *IAMFilerStore) loadIAMConfigFromEntry(content []byte, config *iam_pb.S3ApiConfiguration) error {
|
||||||
for _, ident := range *extended {
|
if err := proto.Unmarshal(content, config); err != nil {
|
||||||
identity := &iam_pb.Identity{}
|
return err
|
||||||
if err := proto.Unmarshal(ident, identity); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
config.Identities = append(config.Identities, identity)
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ifs *IAMFilerStore) saveIAMConfigToEntryExtended(extended *map[string][]byte, config *iam_pb.S3ApiConfiguration) error {
|
func (ifs *IAMFilerStore) saveIAMConfigToEntry(content []byte, config *iam_pb.S3ApiConfiguration) error {
|
||||||
for _, identity := range config.Identities {
|
content, err := proto.Marshal(config)
|
||||||
ident, err := proto.Marshal(identity)
|
if err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return err
|
|
||||||
}
|
|
||||||
(*extended)[identity.Name] = ident
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,14 +50,13 @@ func TestS3Conf(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
content := []byte{}
|
||||||
|
_ = ifs.saveIAMConfigToEntry(content, s3Conf)
|
||||||
s3ConfSaved := &iam_pb.S3ApiConfiguration{}
|
s3ConfSaved := &iam_pb.S3ApiConfiguration{}
|
||||||
extended := make(map[string][]byte)
|
_ = ifs.loadIAMConfigFromEntry(content, s3ConfSaved)
|
||||||
_ = ifs.saveIAMConfigToEntryExtended(&extended, s3Conf)
|
|
||||||
_ = ifs.loadIAMConfigFromEntryExtended(&extended, s3ConfSaved)
|
|
||||||
|
|
||||||
assert.Equal(t, "some_name", s3ConfSaved.Identities[0].Name)
|
assert.Equal(t, "some_name", s3ConfSaved.Identities[0].Name)
|
||||||
assert.Equal(t, "some_read_only_user", s3ConfSaved.Identities[1].Name)
|
assert.Equal(t, "some_read_only_user", s3ConfSaved.Identities[1].Name)
|
||||||
assert.Equal(t, "some_access_key1", s3ConfSaved.Identities[0].Credentials[0].AccessKey)
|
assert.Equal(t, "some_access_key1", s3ConfSaved.Identities[0].Credentials[0].AccessKey)
|
||||||
assert.Equal(t, "some_secret_key2", s3ConfSaved.Identities[1].Credentials[0].SecretKey)
|
assert.Equal(t, "some_secret_key2", s3ConfSaved.Identities[1].Credentials[0].SecretKey)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue