-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command for printing a starter template
- Loading branch information
kroonprins
committed
Jan 22, 2023
1 parent
9b4aeea
commit 9ddb0b4
Showing
6 changed files
with
174 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package new | ||
|
||
import ( | ||
goflag "flag" | ||
|
||
"github.com/bitnami-labs/sealed-secrets/pkg/pflagenv" | ||
"github.com/kroonprins/kube-create-secret/cmd/constants" | ||
"github.com/kroonprins/kube-create-secret/pkg/core" | ||
"github.com/kroonprins/kube-create-secret/pkg/output/marshal" | ||
"github.com/kroonprins/kube-create-secret/pkg/output/write" | ||
"github.com/kroonprins/kube-create-secret/pkg/types" | ||
"github.com/spf13/cobra" | ||
"github.com/thediveo/enumflag/v2" | ||
) | ||
|
||
var ( | ||
config = *core.NewConfig() | ||
templateType types.StarterTemplateType | ||
) | ||
|
||
func init() { | ||
fs := Cmd.PersistentFlags() | ||
fs.VarP(enumflag.NewSlice(&config.OutputFormats, "output", types.FormatIds, enumflag.EnumCaseInsensitive), "output", "o", "Output format. One of: (json, yaml). If not specified the format of the input is used.") | ||
fs.VarP(enumflag.New(&templateType, "type", types.StarterTemplateTypes, enumflag.EnumCaseInsensitive), "type", "t", "Template type. One of: (data, stringData, tls).") | ||
|
||
fs.AddGoFlagSet(goflag.CommandLine) | ||
pflagenv.SetFlagsFromEnv(constants.FLAGENV_PREFIX, fs) | ||
} | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "new", | ||
Aliases: []string{"n"}, | ||
Short: "Print starter template.", | ||
Long: `Print starter template.`, | ||
Example: " kube-create-secret new\n" + | ||
" kube-create-secret new -t tls -o json\n", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
core.Marshallers = []core.Marshaller{ | ||
marshal.NewYamlMarshaller(), | ||
marshal.NewJsonMarshaller(), | ||
} | ||
core.OutputWriters = []core.OutputWriter{ | ||
write.NewStdOutWriter(), | ||
} | ||
|
||
return core.StarterTemplate(config, templateType) | ||
}, | ||
} |
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,91 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/kroonprins/kube-create-secret/pkg/constants" | ||
"github.com/kroonprins/kube-create-secret/pkg/types" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func NewStarterTemplate(config Config, templateType types.StarterTemplateType) (*types.SecretTemplate, error) { | ||
if templateType == types.DATA { | ||
return &types.SecretTemplate{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: constants.SECRET_TEMPLATE_KIND, | ||
APIVersion: constants.SECRET_TEMPLATE_API_VERSION, | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "[insert template name]", | ||
}, | ||
Spec: types.SecretTemplateSpec{ | ||
Secret: corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "[insert secret name]", | ||
Namespace: "[insert namespace] (optional)", | ||
}, | ||
Type: corev1.SecretTypeOpaque, | ||
}, | ||
Data: map[string]string{ | ||
"[insert key]": "ref+[insert provider]://[insert provider config]", | ||
}, | ||
}, | ||
}, nil | ||
} else if templateType == types.STRINGDATA { | ||
return &types.SecretTemplate{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: constants.SECRET_TEMPLATE_KIND, | ||
APIVersion: constants.SECRET_TEMPLATE_API_VERSION, | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "[insert template name]", | ||
}, | ||
Spec: types.SecretTemplateSpec{ | ||
Secret: corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "[insert secret name]", | ||
Namespace: "[insert namespace] (optional)", | ||
}, | ||
Type: corev1.SecretTypeOpaque, | ||
}, | ||
StringData: map[string]string{ | ||
"[insert key]": "ref+[insert provider]://[insert provider config]", | ||
}, | ||
}, | ||
}, nil | ||
} else if templateType == types.TLS { | ||
return &types.SecretTemplate{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: constants.SECRET_TEMPLATE_KIND, | ||
APIVersion: constants.SECRET_TEMPLATE_API_VERSION, | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "[insert template name]", | ||
}, | ||
Spec: types.SecretTemplateSpec{ | ||
Secret: corev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "[insert secret name]", | ||
Namespace: "[insert namespace] (optional)", | ||
}, | ||
Type: corev1.SecretTypeTLS, | ||
}, | ||
Tls: &types.Tls{ | ||
Pkcs12: "ref+[insert provider]://[insert provider config]", | ||
Password: "ref+[insert provider]://[insert provider config] (optional)", | ||
Name: "[insert name] (optional)", | ||
KeyConfig: &types.TlsKeyConfig{ | ||
Name: "[insert name] (optional)", | ||
}, | ||
CrtConfig: &types.TlsCrtConfig{ | ||
Name: "[insert name (optional)]", | ||
ChainDelimiter: "[insert delimiter (optional)]", | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} | ||
return nil, fmt.Errorf("unhandled template type %s", types.StarterTemplateTypes[templateType][0]) | ||
} |
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