-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2586 from MaxMcAdam/anax-2476
Issue 2476 - Update hzn dev service new/start/stop to support secrets
- Loading branch information
Showing
8 changed files
with
111 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package dev | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/open-horizon/anax/common" | ||
"github.com/open-horizon/anax/config" | ||
"github.com/open-horizon/anax/containermessage" | ||
) | ||
|
||
const SECRETS_FILE = "servicesecret" | ||
|
||
// Check for the existence of the user input config file in the project. | ||
func SecretsFileExists(directory string) (bool, error) { | ||
return FileExists(directory, SECRETS_FILE) | ||
} | ||
|
||
type ServiceSecret struct { | ||
Key string `json:"key"` | ||
Value string `json:"value"` | ||
} | ||
|
||
func CreateSecretsFile(directory string) error { | ||
fileContents := ServiceSecret{Key: "My Secret Type", Value: "My Secret Value"} | ||
|
||
return CreateFile(directory, SECRETS_FILE, fileContents) | ||
} | ||
|
||
// Add binds for the provided service secret files if the secret name is specified in a dependent service | ||
func AddDependentServiceSecretBinds(deps []*common.ServiceFile, secretsFiles map[string]string) { | ||
for _, dep := range deps { | ||
typedDeploy := common.DeploymentConfig{} | ||
|
||
if deployBytes, err := json.Marshal(dep.Deployment); err != nil { | ||
fmt.Printf("Failed to marshal deps: %v", err) | ||
} else if err = json.Unmarshal(deployBytes, &typedDeploy); err != nil { | ||
fmt.Printf("Failed to unmarshal deps: %v", err) | ||
} else { | ||
for svcName, svcInfo := range typedDeploy.Services { | ||
for secName, _ := range svcInfo.Secrets { | ||
if svcPath, ok := secretsFiles[secName]; ok { | ||
svcInfo.Binds = append(svcInfo.Binds, fmt.Sprintf("%v:%v/%v", svcPath, config.HZN_SECRETS_MOUNT, secName)) | ||
} else { | ||
fmt.Printf("Warning: Secret %v for service %v not specified with %v command.\n", secName, svcName, SERVICE_START_COMMAND) | ||
} | ||
} | ||
} | ||
} | ||
dep.Deployment = typedDeploy | ||
} | ||
} | ||
|
||
// Add binds for the provided service secret files to the top-level service container if the secret name is in the service deployment | ||
func AddTopLevelServiceSecretBinds(deployment *containermessage.DeploymentDescription, secretsFiles map[string]string) { | ||
for svcName, svcInfo := range deployment.Services { | ||
for secName, _ := range svcInfo.Secrets { | ||
if svcPath, ok := secretsFiles[secName]; ok { | ||
svcInfo.Binds = append(svcInfo.Binds, fmt.Sprintf("%v:%v/%v", svcPath, config.HZN_SECRETS_MOUNT, secName)) | ||
} else { | ||
fmt.Printf("Warning: Secret %v for service %v not specified with %v command.\n", secName, svcName, SERVICE_START_COMMAND) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters