This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #29 from jstrachan/changes
fix: add verify of secrets
- Loading branch information
Showing
10 changed files
with
138 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package secrets | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/jenkins-x-labs/helmboot/pkg/common" | ||
"github.com/jenkins-x-labs/helmboot/pkg/secretmgr/factory" | ||
"github.com/jenkins-x/jx/pkg/cmd/helper" | ||
"github.com/jenkins-x/jx/pkg/cmd/templates" | ||
"github.com/jenkins-x/jx/pkg/log" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
verifyLong = templates.LongDesc(` | ||
Verifies the secrets are populated correctly | ||
`) | ||
|
||
verifyExample = templates.Examples(` | ||
# verifies the secrets are setup correctly | ||
%s secrets verify | ||
`) | ||
) | ||
|
||
// VerifyOptions the options for viewing running PRs | ||
type VerifyOptions struct { | ||
factory.KindResolver | ||
File string | ||
} | ||
|
||
// NewCmdVerify creates a command object for the command | ||
func NewCmdVerify() (*cobra.Command, *VerifyOptions) { | ||
o := &VerifyOptions{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "verify", | ||
Short: "Verifies the secrets are populated correctly", | ||
Long: verifyLong, | ||
Example: fmt.Sprintf(verifyExample, common.BinaryName), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := o.Run() | ||
helper.CheckErr(err) | ||
}, | ||
} | ||
AddKindResolverFlags(cmd, &o.KindResolver) | ||
return cmd, o | ||
} | ||
|
||
// Run implements the command | ||
func (o *VerifyOptions) Run() error { | ||
err := o.VerifySecrets() | ||
if err != nil { | ||
return err | ||
} | ||
log.Logger().Infof("secrets are valid") | ||
return nil | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package secretmgr | ||
|
||
import ( | ||
"github.com/jenkins-x/jx/pkg/util" | ||
"github.com/pkg/errors" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
var expectedSecretPaths = []string{ | ||
"secrets.adminUser.username", | ||
"secrets.adminUser.password", | ||
"secrets.hmacToken", | ||
"secrets.pipelineUser.username", | ||
"secrets.pipelineUser.email", | ||
"secrets.pipelineUser.token", | ||
} | ||
|
||
// VerifyBootSecrets verifies the boot secrets | ||
func VerifyBootSecrets(secretsYAML string) error { | ||
data := map[string]interface{}{} | ||
|
||
err := yaml.Unmarshal([]byte(secretsYAML), &data) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to unmarshal secrets YAML") | ||
} | ||
|
||
// simple validation for now, using presence of a string value | ||
for _, path := range expectedSecretPaths { | ||
value := util.GetMapValueAsStringViaPath(data, path) | ||
if value == "" { | ||
return errors.Errorf("missing secret entry: %s", path) | ||
} | ||
} | ||
return nil | ||
} |