Skip to content

Commit 6abddb1

Browse files
authored
Merge pull request #243 from mengqiy/cp_if
certprovider interface
2 parents a51497f + 76c1294 commit 6abddb1

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

pkg/webhook/doc.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package webhook
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package certprovisioner
18+
19+
// CertProvisioner is an interface to provision the serving certificate.
20+
type CertProvisioner interface {
21+
// ProvisionServingCert returns the key, serving certificate and the CA certificate.
22+
ProvisionServingCert() (key []byte, cert []byte, caCert []byte, err error)
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
Package certprovisioner provides an interface and implementation to provision certificates.
19+
20+
Create a implementation instance of certprovisioner.
21+
22+
cp := SelfSignedCertProvisioner{
23+
// your configuration
24+
}
25+
26+
Provision the certificates.
27+
key, cert, caCert, err := cp.ProvisionServingCert()
28+
if err != nil {
29+
// handle error
30+
}
31+
*/
32+
package certprovisioner
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package certprovisioner
18+
19+
func ExampleSelfSignedCertProvisioner() {
20+
cp := SelfSignedCertProvisioner{
21+
Organization: "k8s.io",
22+
DNSNames: []string{"myDNSName"},
23+
ValidDays: 365,
24+
}
25+
26+
key, cert, caCert, err := cp.ProvisionServingCert()
27+
if err != nil {
28+
// handle error
29+
}
30+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package certprovisioner
18+
19+
// SelfSignedCertProvisioner implements the CertProvisioner interface.
20+
// It provisions self-signed certificates.
21+
type SelfSignedCertProvisioner struct {
22+
// Required DNS names for your certificate
23+
DNSNames []string
24+
// Organization name
25+
Organization string
26+
// Number of days the certificate will be valid for.
27+
ValidDays int
28+
}
29+
30+
var _ CertProvisioner = &SelfSignedCertProvisioner{}
31+
32+
// ProvisionServingCert generates a CA and a serving cert. It returns the key, serving cert, CA cert and a potential error.
33+
func (cp *SelfSignedCertProvisioner) ProvisionServingCert() (key []byte, cert []byte, caCert []byte, err error) {
34+
// TODO: implement this
35+
return nil, nil, nil, nil
36+
}

0 commit comments

Comments
 (0)