Skip to content

Commit 62cad9b

Browse files
author
Mengqi Yu
committed
cert provisioner
1 parent 872f043 commit 62cad9b

File tree

10 files changed

+722
-22
lines changed

10 files changed

+722
-22
lines changed

pkg/admission/certprovisioner/certprovisioner.go renamed to pkg/admission/certinput/certprovisioner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package certprovisioner
17+
package certinput
1818

1919
// Certs hosts a private key, its corresponding serving certificate and
2020
// the CA certificate that signs the serving certificate.
@@ -24,8 +24,8 @@ type Certs struct {
2424
CACert []byte
2525
}
2626

27-
// CertProvisioner is an interface to provision the serving certificate.
28-
type CertProvisioner interface {
27+
// CertInput is an interface to provision the serving certificate.
28+
type CertInput interface {
2929
// ProvisionServingCert returns a Certs struct.
30-
ProvisionServingCert() (*Certs, error)
30+
ProvisionServingCert(CommonName string) (*Certs, error)
3131
}

pkg/admission/certprovisioner/certprovisioner_test.go renamed to pkg/admission/certinput/certprovisioner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package certprovisioner
17+
package certinput
1818

1919
import "fmt"
2020

pkg/admission/certprovisioner/doc.go renamed to pkg/admission/certinput/doc.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ Package certprovisioner provides an interface and implementation to provision ce
1919
2020
Create a implementation instance of certprovisioner.
2121
22-
cp := SelfSignedCertProvisioner{
23-
CommonName: "foo.bar.com"
24-
}
22+
cp := SelfSignedCertInput{}
2523
2624
Provision the certificates.
27-
certs, err := cp.ProvisionServingCert()
25+
certs, err := cp.ProvisionServingCert("foo.bar.com")
2826
if err != nil {
2927
// handle error
3028
}
3129
*/
32-
package certprovisioner
30+
package certinput

pkg/admission/certprovisioner/selfsignedcertprovisioner.go renamed to pkg/admission/certinput/selfsignedcertprovisioner.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package certprovisioner
17+
package certinput
1818

1919
import (
2020
"crypto/x509"
@@ -28,21 +28,18 @@ func ServiceToCommonName(serviceNamespace, serviceName string) string {
2828
return fmt.Sprintf("%s.%s.svc", serviceName, serviceNamespace)
2929
}
3030

31-
// SelfSignedCertProvisioner implements the CertProvisioner interface.
31+
// SelfSignedCertInput implements the CertInput interface.
3232
// It provisions self-signed certificates.
33-
type SelfSignedCertProvisioner struct {
34-
// Required Common Name
35-
CommonName string
36-
}
33+
type SelfSignedCertInput struct{}
3734

38-
var _ CertProvisioner = &SelfSignedCertProvisioner{}
35+
var _ CertInput = &SelfSignedCertInput{}
3936

4037
// ProvisionServingCert creates and returns a CA certificate, certificate and
4138
// key for the server. serverKey and serverCert are used by the server
4239
// to establish trust for clients, CA certificate is used by the
4340
// client to verify the server authentication chain.
4441
// The cert will be valid for 365 days.
45-
func (cp *SelfSignedCertProvisioner) ProvisionServingCert() (*Certs, error) {
42+
func (cp *SelfSignedCertInput) ProvisionServingCert(commonName string) (*Certs, error) {
4643
signingKey, err := cert.NewPrivateKey()
4744
if err != nil {
4845
return nil, fmt.Errorf("failed to create the CA private key: %v", err)
@@ -57,7 +54,7 @@ func (cp *SelfSignedCertProvisioner) ProvisionServingCert() (*Certs, error) {
5754
}
5855
signedCert, err := cert.NewSignedCert(
5956
cert.Config{
60-
CommonName: cp.CommonName,
57+
CommonName: commonName,
6158
Usages: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
6259
},
6360
key, signingCert, signingKey,

pkg/admission/certprovisioner/selfsignedcertprovisioner_test.go renamed to pkg/admission/certinput/selfsignedcertprovisioner_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package certprovisioner
17+
package certinput
1818

1919
import (
2020
"crypto/x509"
@@ -24,8 +24,8 @@ import (
2424

2525
func TestProvisionServingCert(t *testing.T) {
2626
cn := "mysvc.myns.svc"
27-
cp := SelfSignedCertProvisioner{CommonName: cn}
28-
certs, _ := cp.ProvisionServingCert()
27+
cp := SelfSignedCertInput{}
28+
certs, _ := cp.ProvisionServingCert(cn)
2929

3030
// First, create the set of root certificates. For this example we only
3131
// have one. It's also possible to omit this in order to use the

0 commit comments

Comments
 (0)