object: allocate keys for user after the creation
The access/secrets keys for the user struct need to allocate only if
ceph user creation succeeds.
Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
(cherry picked from commit 60da73a786)
This commit is contained in:
1 parent
c58c9ee356
commit
6edbd1bcb8
2 files changed
+16
-4
No files matched your search
@@ -346,6 +346,9 @@ func (r *ReconcileObjectStoreUser) createorUpdateCephUser(u *cephv1.CephObjectSt
|
||||
}
|
||||
|
||||
// Set access and secret key
|
||||
if r.userConfig.Keys == nil {
|
||||
r.userConfig.Keys = make([]admin.UserKeySpec, 1)
|
||||
}
|
||||
r.userConfig.Keys[0].AccessKey = user.Keys[0].AccessKey
|
||||
r.userConfig.Keys[0].SecretKey = user.Keys[0].SecretKey
|
||||
logger.Info(logCreateOrUpdate)
|
||||
@@ -393,7 +396,6 @@ func generateUserConfig(user *cephv1.CephObjectStoreUser) admin.User {
|
||||
userConfig := admin.User{
|
||||
ID: user.Name,
|
||||
DisplayName: displayName,
|
||||
Keys: make([]admin.UserKeySpec, 1),
|
||||
}
|
||||
|
||||
defaultMaxBuckets := 1000
|
||||
|
||||
@@ -290,8 +290,9 @@ func TestCephObjectStoreUserController(t *testing.T) {
|
||||
newMultisiteAdminOpsCtxFunc = func(objContext *cephobject.Context, spec *cephv1.ObjectStoreSpec) (*cephobject.AdminOpsContext, error) {
|
||||
mockClient := &cephobject.MockClient{
|
||||
MockDo: func(req *http.Request) (*http.Response, error) {
|
||||
if (req.URL.RawQuery == "display-name=my-user&format=json&max-buckets=1000&uid=my-user" && (req.Method == http.MethodGet || req.Method == http.MethodPost) && req.URL.Path == "rook-ceph-rgw-my-store.mycluster.svc/admin/user") ||
|
||||
(req.URL.RawQuery == "enabled=false&format=json&max-objects=-1&max-size=-1"a="a-type=user&uid=my-user" && req.Method == http.MethodPut && req.URL.Path == "rook-ceph-rgw-my-store.mycluster.svc/admin/user") {
|
||||
if (req.URL.RawQuery == "display-name=my-user&format=json&max-buckets=1000&uid=my-user" && req.Method == http.MethodPost && req.URL.Path == "rook-ceph-rgw-my-store.mycluster.svc/admin/user") ||
|
||||
(req.URL.RawQuery == "enabled=false&format=json&max-objects=-1&max-size=-1"a="a-type=user&uid=my-user" && req.Method == http.MethodPut && req.URL.Path == "rook-ceph-rgw-my-store.mycluster.svc/admin/user") ||
|
||||
(req.URL.RawQuery == "format=json&uid=my-user" && req.Method == http.MethodGet && req.URL.Path == "rook-ceph-rgw-my-store.mycluster.svc/admin/user") {
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(userCreateJSON))),
|
||||
@@ -361,7 +362,16 @@ func TestCreateorUpdateCephUser(t *testing.T) {
|
||||
return nil, fmt.Errorf("unexpected url path %q", req.URL.Path)
|
||||
}
|
||||
|
||||
if req.Method == http.MethodGet || req.Method == http.MethodPost {
|
||||
if req.Method == http.MethodGet {
|
||||
if req.URL.RawQuery == "format=json&uid=my-user" {
|
||||
return &http.Response{
|
||||
StatusCode: 200,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(userCreateJSON))),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
if req.Method == http.MethodPost {
|
||||
if req.URL.RawQuery == "display-name=my-user&format=json&max-buckets=1000&uid=my-user" ||
|
||||
req.URL.RawQuery == "display-name=my-user&format=json&max-buckets=200&uid=my-user" ||
|
||||
req.URL.RawQuery == "display-name=my-user&format=json&max-buckets=1000&uid=my-user&user-caps=users%3Dread%3Bbuckets%3Dread%3B" ||
|
||||
|
||||
Reference in new issue
Block a user