Skip to content

Commit

Permalink
Merge pull request open-horizon#3909 from LiilyZhang/zhangl/issue3908
Browse files Browse the repository at this point in the history
Issue open-horizon#3908 - Bug: CLI for node level secrets not applyin…
  • Loading branch information
LiilyZhang authored Sep 29, 2023
2 parents 6c44853 + 73b8d4e commit a85861c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
6 changes: 3 additions & 3 deletions agreementbot/secure_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,11 +1200,11 @@ func (a *SecureAPI) errCheck(err error, action string, info *SecretRequestInfo)
// build the original secret name
var secretName string
if info.user != "" && info.node != "" {
secretName = "user/" + info.user + "node/" + info.node + cliutils.AddSlash(info.vaultSecretName)
secretName = "/user/" + info.user + "/node/" + info.node + cliutils.AddSlash(info.vaultSecretName)
} else if info.user != "" {
secretName = "user/" + info.user + cliutils.AddSlash(info.vaultSecretName)
secretName = "/user/" + info.user + cliutils.AddSlash(info.vaultSecretName)
} else if info.node != "" {
secretName = "node/" + info.node + cliutils.AddSlash(info.vaultSecretName)
secretName = "/node/" + info.node + cliutils.AddSlash(info.vaultSecretName)
} else {
secretName = info.vaultSecretName
}
Expand Down
33 changes: 25 additions & 8 deletions cli/secrets_manager/secrets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ func SecretList(org, credToUse, secretName, secretNodeId string) {
secretName = secretName[:len(secretName)-1]
}

if !strings.Contains(secretName, "/node") && secretNodeId != "" {
// add /node/{nodeID} to the path
if strings.HasPrefix(secretName, "/") {
secretName = strings.TrimPrefix(secretName, "/")
}

if !strings.Contains(secretName, "node/") && secretNodeId != "" {
// add node/{nodeID} to the path
secretName = getSecretPathForNodeLevelSecret(secretName, secretNodeId)
}
// if given secretName := "", nodeId is specified, then secretName will be convert to "node/{nodeId}"
Expand Down Expand Up @@ -166,8 +170,12 @@ func SecretAdd(org, credToUse, secretName, secretNodeId, secretFile, secretKey,
secretName = secretName[:len(secretName)-1]
}

if !strings.Contains(secretName, "/node") && secretNodeId != "" {
// add /node/{nodeID} to the path
if strings.HasPrefix(secretName, "/") {
secretName = strings.TrimPrefix(secretName, "/")
}

if !strings.Contains(secretName, "node/") && secretNodeId != "" {
// add node/{nodeID} to the path
secretName = getSecretPathForNodeLevelSecret(secretName, secretNodeId)
}

Expand Down Expand Up @@ -259,8 +267,12 @@ func SecretRemove(org, credToUse, secretName, secretNodeId string, forceRemoval
secretName = secretName[:len(secretName)-1]
}

if !strings.Contains(secretName, "/node") && secretNodeId != "" {
// add /node/{nodeID} to the path
if strings.HasPrefix(secretName, "/") {
secretName = strings.TrimPrefix(secretName, "/")
}

if !strings.Contains(secretName, "node/") && secretNodeId != "" {
// add node/{nodeID} to the path
secretName = getSecretPathForNodeLevelSecret(secretName, secretNodeId)
}

Expand Down Expand Up @@ -299,8 +311,12 @@ func SecretRead(org, credToUse, secretName, secretNodeId string) {
secretName = secretName[:len(secretName)-1]
}

if !strings.Contains(secretName, "/node") && secretNodeId != "" {
// add /node/{nodeID} to the path
if strings.HasPrefix(secretName, "/") {
secretName = strings.TrimPrefix(secretName, "/")
}

if !strings.Contains(secretName, "node/") && secretNodeId != "" {
// add node/{nodeID} to the path
secretName = getSecretPathForNodeLevelSecret(secretName, secretNodeId)
}

Expand Down Expand Up @@ -328,6 +344,7 @@ func SecretRead(org, credToUse, secretName, secretNodeId string) {

func getSecretPathForNodeLevelSecret(secretName string, secretNodeId string) string {
secretName = strings.TrimSpace(secretName)
secretName = strings.TrimPrefix(secretName, "/")
if secretName == "" {
secretName = fmt.Sprintf("node/%v", secretNodeId)
} else {
Expand Down

0 comments on commit a85861c

Please sign in to comment.