mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
cleanup: address golangci 'funcorder' linter problems
The new 'funcorder' linter expects all public functions to be placed before private functions of a struct. Many private functions needed moving further down into their files. Some files had many issues reported. To reduce the churn in those files, they have been annotated with a `//nolint:funcorder` comment. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
0907f39d95
commit
0a22e3a186
@ -43,6 +43,48 @@ type Credentials struct {
|
||||
KeyFile string
|
||||
}
|
||||
|
||||
// NewUserCredentials creates new user credentials from secret.
|
||||
func NewUserCredentials(secrets map[string]string) (*Credentials, error) {
|
||||
return newCredentialsFromSecret(credUserID, credUserKey, secrets)
|
||||
}
|
||||
|
||||
// NewAdminCredentials creates new admin credentials from secret.
|
||||
func NewAdminCredentials(secrets map[string]string) (*Credentials, error) {
|
||||
// Use userID and userKey if found else fallback to adminID and adminKey
|
||||
if cred, err := newCredentialsFromSecret(credUserID, credUserKey, secrets); err == nil {
|
||||
return cred, nil
|
||||
}
|
||||
log.WarningLogMsg("adminID and adminKey are deprecated, please use userID and userKey instead")
|
||||
|
||||
return newCredentialsFromSecret(credAdminID, credAdminKey, secrets)
|
||||
}
|
||||
|
||||
// NewUserCredentialsWithMigration takes secret map from the request and validate it is
|
||||
// a migration secret, if yes, it continues to create CR from it after parsing the migration
|
||||
// secret. If it is not a migration it will continue the attempt to create credentials from it
|
||||
// without parsing the secret. This function returns credentials and error.
|
||||
func NewUserCredentialsWithMigration(secrets map[string]string) (*Credentials, error) {
|
||||
if isMigrationSecret(secrets) {
|
||||
migSecret, err := ParseAndSetSecretMapFromMigSecret(secrets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
secrets = migSecret
|
||||
}
|
||||
cr, cErr := NewUserCredentials(secrets)
|
||||
if cErr != nil {
|
||||
return nil, cErr
|
||||
}
|
||||
|
||||
return cr, nil
|
||||
}
|
||||
|
||||
// DeleteCredentials removes the KeyFile.
|
||||
func (cr *Credentials) DeleteCredentials() {
|
||||
// don't complain about unhandled error
|
||||
_ = os.Remove(cr.KeyFile)
|
||||
}
|
||||
|
||||
func storeKey(key string) (string, error) {
|
||||
tmpfile, err := os.CreateTemp(tmpKeyFileLocation, tmpKeyFileNamePrefix)
|
||||
if err != nil {
|
||||
@ -99,28 +141,6 @@ func newCredentialsFromSecret(idField, keyField string, secrets map[string]strin
|
||||
return c, err
|
||||
}
|
||||
|
||||
// DeleteCredentials removes the KeyFile.
|
||||
func (cr *Credentials) DeleteCredentials() {
|
||||
// don't complain about unhandled error
|
||||
_ = os.Remove(cr.KeyFile)
|
||||
}
|
||||
|
||||
// NewUserCredentials creates new user credentials from secret.
|
||||
func NewUserCredentials(secrets map[string]string) (*Credentials, error) {
|
||||
return newCredentialsFromSecret(credUserID, credUserKey, secrets)
|
||||
}
|
||||
|
||||
// NewAdminCredentials creates new admin credentials from secret.
|
||||
func NewAdminCredentials(secrets map[string]string) (*Credentials, error) {
|
||||
// Use userID and userKey if found else fallback to adminID and adminKey
|
||||
if cred, err := newCredentialsFromSecret(credUserID, credUserKey, secrets); err == nil {
|
||||
return cred, nil
|
||||
}
|
||||
log.WarningLogMsg("adminID and adminKey are deprecated, please use userID and userKey instead")
|
||||
|
||||
return newCredentialsFromSecret(credAdminID, credAdminKey, secrets)
|
||||
}
|
||||
|
||||
// GetMonValFromSecret returns monitors from secret.
|
||||
func GetMonValFromSecret(secrets map[string]string) (string, error) {
|
||||
if mons, ok := secrets[credMonitors]; ok {
|
||||
@ -160,23 +180,3 @@ func isMigrationSecret(secrets map[string]string) bool {
|
||||
// was hit on migration request compared to general one.
|
||||
return len(secrets) != 0 && secrets[migUserKey] != ""
|
||||
}
|
||||
|
||||
// NewUserCredentialsWithMigration takes secret map from the request and validate it is
|
||||
// a migration secret, if yes, it continues to create CR from it after parsing the migration
|
||||
// secret. If it is not a migration it will continue the attempt to create credentials from it
|
||||
// without parsing the secret. This function returns credentials and error.
|
||||
func NewUserCredentialsWithMigration(secrets map[string]string) (*Credentials, error) {
|
||||
if isMigrationSecret(secrets) {
|
||||
migSecret, err := ParseAndSetSecretMapFromMigSecret(secrets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
secrets = migSecret
|
||||
}
|
||||
cr, cErr := NewUserCredentials(secrets)
|
||||
if cErr != nil {
|
||||
return nil, cErr
|
||||
}
|
||||
|
||||
return cr, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user