From 8223ae325b0bd9ab232a3f405737bd8146ffac06 Mon Sep 17 00:00:00 2001 From: gman Date: Thu, 14 Feb 2019 14:38:53 +0100 Subject: [PATCH] addressed review comments --- pkg/cephfs/cephuser.go | 26 ++++++++++++++++++++------ pkg/util/stripsecrets.go | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/cephfs/cephuser.go b/pkg/cephfs/cephuser.go index fb06d5bf3..113933019 100644 --- a/pkg/cephfs/cephuser.go +++ b/pkg/cephfs/cephuser.go @@ -61,23 +61,34 @@ func getSingleCephEntity(args ...string) (*cephEntity, error) { return &ents[0], nil } +func genUserIDs(adminCr *credentials, volID volumeID) (adminID, userID string) { + return cephEntityClientPrefix + adminCr.id, cephEntityClientPrefix + getCephUserName(volID) +} + func getCephUser(volOptions *volumeOptions, adminCr *credentials, volID volumeID) (*cephEntity, error) { + adminID, userID := genUserIDs(adminCr, volID) + return getSingleCephEntity( "-m", volOptions.Monitors, - "-n", cephEntityClientPrefix+adminCr.id, "--key="+adminCr.key, + "-n", adminID, + "--key="+adminCr.key, "-c", cephConfigPath, "-f", "json", - "auth", "get", cephEntityClientPrefix+getCephUserName(volID), + "auth", "get", userID, ) } func createCephUser(volOptions *volumeOptions, adminCr *credentials, volID volumeID) (*cephEntity, error) { + adminID, userID := genUserIDs(adminCr, volID) + return getSingleCephEntity( "-m", volOptions.Monitors, - "-n", cephEntityClientPrefix+adminCr.id, "--key="+adminCr.key, + "-n", adminID, + "--key="+adminCr.key, "-c", cephConfigPath, "-f", "json", - "auth", "get-or-create", cephEntityClientPrefix+getCephUserName(volID), + "auth", "get-or-create", userID, + // User capabilities "mds", fmt.Sprintf("allow rw path=%s", getVolumeRootPathCeph(volID)), "mon", "allow r", "osd", fmt.Sprintf("allow rw pool=%s namespace=%s", volOptions.Pool, getVolumeNamespace(volID)), @@ -85,10 +96,13 @@ func createCephUser(volOptions *volumeOptions, adminCr *credentials, volID volum } func deleteCephUser(volOptions *volumeOptions, adminCr *credentials, volID volumeID) error { + adminID, userID := genUserIDs(adminCr, volID) + return execCommandErr("ceph", "-m", volOptions.Monitors, - "-n", cephEntityClientPrefix+adminCr.id, "--key="+adminCr.key, + "-n", adminID, + "--key="+adminCr.key, "-c", cephConfigPath, - "auth", "rm", cephEntityClientPrefix+getCephUserName(volID), + "auth", "rm", userID, ) } diff --git a/pkg/util/stripsecrets.go b/pkg/util/stripsecrets.go index 7a69c56a2..8b818de9d 100644 --- a/pkg/util/stripsecrets.go +++ b/pkg/util/stripsecrets.go @@ -1,5 +1,5 @@ /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.