forked from kubernetes/kops
/
create_secret_tls.go
169 lines (164 loc) · 5.02 KB
/
create_secret_tls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
//
//import (
// "fmt"
//
// "crypto/x509"
// "github.com/golang/glog"
// "github.com/spf13/cobra"
// "k8s.io/kops/upup/pkg/fi"
// "net"
// "strings"
//)
//
//type CreateSecretsCommand struct {
// Id string
// Type string
//
// Usage string
// Subject string
// AlternateNames []string
//}
//
//var createSecretsCommand CreateSecretsCommand
//
//func init() {
// cmd := &cobra.Command{
// Use: "secret",
// Short: "Create secrets",
// Long: `Create secrets.`,
// Run: func(cmd *cobra.Command, args []string) {
// err := createSecretsCommand.Run()
// if err != nil {
// exitWithError(err)
// }
// },
// }
//
// createCmd.AddCommand(cmd)
//
// cmd.Flags().StringVarP(&createSecretsCommand.Type, "type", "", "", "Type of secret to create")
// cmd.Flags().StringVarP(&createSecretsCommand.Id, "id", "", "", "Id of secret to create")
// cmd.Flags().StringVarP(&createSecretsCommand.Usage, "usage", "", "", "Usage of secret (for SSL certificate)")
// cmd.Flags().StringVarP(&createSecretsCommand.Subject, "subject", "", "", "Subject (for SSL certificate)")
// cmd.Flags().StringSliceVarP(&createSecretsCommand.AlternateNames, "san", "", nil, "Alternate name (for SSL certificate)")
//}
//
//func (cmd *CreateSecretsCommand) Run() error {
// if cmd.Id == "" {
// return fmt.Errorf("id is required")
// }
//
// if cmd.Type == "" {
// return fmt.Errorf("type is required")
// }
//
// // TODO: Prompt before replacing?
// // TODO: Keep history?
//
// if strings.ToLower(cmd.Type) == strings.ToLower(fi.SecretTypeSecret) {
// return fmt.Errorf("creating secrets of type %q not (currently) supported", cmd.Type)
// //{
// // secretStore, err := rootCommand.SecretStore()
// // if err != nil {
// // return err
// // }
// // secret, err := fi.CreateSecret()
// // if err != nil {
// // return fmt.Errorf("error creating secret: %v", err)
// // }
// // _, created, err := secretStore.GetOrCreateSecret(cmd.Id, secret)
// // if err != nil {
// // return fmt.Errorf("error creating secret: %v", err)
// // }
// // if !created {
// // return fmt.Errorf("secret already exists")
// // }
// // return nil
// //}
// }
//
// if strings.ToLower(cmd.Type) == strings.ToLower(fi.SecretTypeKeypair) {
// return fmt.Errorf("creating secrets of type %q not (currently) supported", cmd.Type)
// //
// //// TODO: Create a rotate command which keeps the same values?
// //// Or just do it here a "replace" action - existing=fail, replace or rotate
// //// TODO: Create a CreateKeypair class, move to fi (this is duplicated code)
// //{
// // if cmd.Subject == "" {
// // return fmt.Errorf("subject is required")
// // }
// //
// // subject, err := parsePkixName(cmd.Subject)
// // if err != nil {
// // return fmt.Errorf("Error parsing subject: %v", err)
// // }
// // template := &x509.Certificate{
// // Subject: *subject,
// // BasicConstraintsValid: true,
// // IsCA: false,
// // }
// //
// // if len(template.Subject.ToRDNSequence()) == 0 {
// // return fmt.Errorf("Subject name was empty")
// // }
// //
// // switch cmd.Usage {
// // case "client":
// // template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}
// // template.KeyUsage = x509.KeyUsageDigitalSignature
// // break
// //
// // case "server":
// // template.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
// // template.KeyUsage = x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment
// // break
// //
// // default:
// // return fmt.Errorf("unknown usage: %q", cmd.Usage)
// // }
// //
// // for _, san := range cmd.AlternateNames {
// // san = strings.TrimSpace(san)
// // if san == "" {
// // continue
// // }
// // if ip := net.ParseIP(san); ip != nil {
// // template.IPAddresses = append(template.IPAddresses, ip)
// // } else {
// // template.DNSNames = append(template.DNSNames, san)
// // }
// // }
// //
// // caStore, err := rootCommand.KeyStore()
// // if err != nil {
// // return err
// // }
// //
// // // TODO: Allow resigning of the existing private key?
// //
// // _, _, err = caStore.CreateKeypair(cmd.Id, template)
// // if err != nil {
// // return fmt.Errorf("error creating keypair %v", err)
// // }
// // return nil
// }
//
// if strings.ToLower(cmd.Type) == strings.ToLower(fi.SecretTypeSSHPublicKey) {
// return fmt.Errorf("creating secrets of type %q not (currently) supported", cmd.Type)
// }
//
// return fmt.Errorf("secret type not known: %q", cmd.Type)
//}