-
Notifications
You must be signed in to change notification settings - Fork 788
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for generated secrets in schemas
If `"default":"<generated>”` is used on a token or a password then it will default to a generated secret Signed-off-by: Pete Muir <pmuir@bleepbleep.org.uk>
- Loading branch information
Showing
7 changed files
with
109 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
{ | ||
"$id": "https:/jenkins-x.io/tests/basicTypes.schema.json", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"description": "test values.yaml", | ||
"type": "object", | ||
"properties": { | ||
"tokenValue": { | ||
"type": "string", | ||
"format": "token", | ||
"default":"<generated>" | ||
} | ||
} | ||
} |
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,34 @@ | ||
package secrets | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/sethvargo/go-password/password" | ||
) | ||
|
||
const ( | ||
allowedSymbols = "~!#%^_+-=?,." | ||
length = 20 | ||
numDigits = 4 | ||
numSymbols = 2 | ||
upperCaseAllowed = true | ||
allowRepeat = true | ||
) | ||
|
||
// DefaultGenerateSecret generates a secret using sensible defaults | ||
func DefaultGenerateSecret() (string, error) { | ||
input := password.GeneratorInput{ | ||
Symbols: allowedSymbols, | ||
} | ||
|
||
generator, err := password.NewGenerator(&input) | ||
if err != nil { | ||
return "", errors.Wrap(err, "unable to create password generator") | ||
} | ||
|
||
secret, err := generator.Generate(length, numDigits, numSymbols, !upperCaseAllowed, allowRepeat) | ||
|
||
if err != nil { | ||
return "", errors.Wrap(err, "unable to generate secret") | ||
} | ||
return secret, 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