11package autoregenerate_after_expiry
22
33import (
4- "encoding/json"
54 "fmt"
65
76 "github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatainterfaces"
@@ -10,68 +9,22 @@ import (
109 "k8s.io/apimachinery/pkg/util/sets"
1110)
1211
13- // TODO move to openshift/api
14- const AutoRegenerateAfterOfflineExpiryAnnotation = "certificates.openshift.io/auto-regenerate-after-offline-expiry"
12+ const annotationName string = "certificates.openshift.io/auto-regenerate-after-offline-expiry"
1513
16- type AutoRegenerateAfterOfflineExpiryRequirement struct {
17- name string
18- }
14+ type AutoRegenerateAfterOfflineExpiryRequirement struct {}
1915
2016func NewAutoRegenerateAfterOfflineExpiryRequirement () tlsmetadatainterfaces.Requirement {
21- return AutoRegenerateAfterOfflineExpiryRequirement {
22- name : "autoregenerate-after-expiry" ,
23- }
24- }
25-
26- func (o AutoRegenerateAfterOfflineExpiryRequirement ) InspectRequirement (rawData []* certgraphapi.PKIList ) (tlsmetadatainterfaces.RequirementResult , error ) {
27- pkiInfo , err := tlsmetadatainterfaces .ProcessByLocation (rawData )
28- if err != nil {
29- return nil , fmt .Errorf ("transforming raw data %v: %w" , o .GetName (), err )
30- }
31-
32- ownershipJSONBytes , err := json .MarshalIndent (pkiInfo , "" , " " )
33- if err != nil {
34- return nil , fmt .Errorf ("failure marshalling %v.json: %w" , o .GetName (), err )
35- }
36- markdown , err := generateAutoRegenerateAfterOfflineExpiryshipMarkdown (pkiInfo )
37- if err != nil {
38- return nil , fmt .Errorf ("failure marshalling %v.md: %w" , o .GetName (), err )
39- }
40- violations := generateViolationJSON (pkiInfo )
41- violationJSONBytes , err := json .MarshalIndent (violations , "" , " " )
42- if err != nil {
43- return nil , fmt .Errorf ("failure marshalling %v-violations.json: %w" , o .GetName (), err )
44- }
45-
46- return tlsmetadatainterfaces .NewRequirementResult (
47- o .GetName (),
48- ownershipJSONBytes ,
49- markdown ,
50- violationJSONBytes )
51- }
52-
53- func generateViolationJSON (pkiInfo * certgraphapi.PKIRegistryInfo ) * certgraphapi.PKIRegistryInfo {
54- ret := & certgraphapi.PKIRegistryInfo {}
55-
56- for i := range pkiInfo .CertKeyPairs {
57- curr := pkiInfo .CertKeyPairs [i ]
58- regenerates , _ := tlsmetadatainterfaces .AnnotationValue (curr .CertKeyInfo .SelectedCertMetadataAnnotations , AutoRegenerateAfterOfflineExpiryAnnotation )
59- if len (regenerates ) == 0 {
60- ret .CertKeyPairs = append (ret .CertKeyPairs , curr )
61- }
62- }
63- for i := range pkiInfo .CertificateAuthorityBundles {
64- curr := pkiInfo .CertificateAuthorityBundles [i ]
65- regenerates , _ := tlsmetadatainterfaces .AnnotationValue (curr .CABundleInfo .SelectedCertMetadataAnnotations , AutoRegenerateAfterOfflineExpiryAnnotation )
66- if len (regenerates ) == 0 {
67- ret .CertificateAuthorityBundles = append (ret .CertificateAuthorityBundles , curr )
68- }
69- }
70-
71- return ret
17+ return tlsmetadatainterfaces .NewAnnotationRequirement (
18+ // requirement name
19+ "autoregenerate-after-expiry" ,
20+ // cert or configmap annotation
21+ annotationName ,
22+ // function which generates markdown report
23+ generateAutoRegenerateAfterOfflineExpiryMarkdownFn ,
24+ )
7225}
7326
74- func generateAutoRegenerateAfterOfflineExpiryshipMarkdown (pkiInfo * certgraphapi.PKIRegistryInfo ) ([]byte , error ) {
27+ func generateAutoRegenerateAfterOfflineExpiryMarkdownFn (pkiInfo * certgraphapi.PKIRegistryInfo ) ([]byte , error ) {
7528 compliantCertsByOwner := map [string ][]certgraphapi.PKIRegistryInClusterCertKeyPair {}
7629 violatingCertsByOwner := map [string ][]certgraphapi.PKIRegistryInClusterCertKeyPair {}
7730 compliantCABundlesByOwner := map [string ][]certgraphapi.PKIRegistryInClusterCABundle {}
@@ -80,7 +33,7 @@ func generateAutoRegenerateAfterOfflineExpiryshipMarkdown(pkiInfo *certgraphapi.
8033 for i := range pkiInfo .CertKeyPairs {
8134 curr := pkiInfo .CertKeyPairs [i ]
8235 owner := curr .CertKeyInfo .OwningJiraComponent
83- regenerates , _ := tlsmetadatainterfaces .AnnotationValue (curr .CertKeyInfo .SelectedCertMetadataAnnotations , AutoRegenerateAfterOfflineExpiryAnnotation )
36+ regenerates , _ := tlsmetadatainterfaces .AnnotationValue (curr .CertKeyInfo .SelectedCertMetadataAnnotations , annotationName )
8437 if len (regenerates ) == 0 {
8538 violatingCertsByOwner [owner ] = append (violatingCertsByOwner [owner ], curr )
8639 continue
@@ -91,7 +44,7 @@ func generateAutoRegenerateAfterOfflineExpiryshipMarkdown(pkiInfo *certgraphapi.
9144 for i := range pkiInfo .CertificateAuthorityBundles {
9245 curr := pkiInfo .CertificateAuthorityBundles [i ]
9346 owner := curr .CABundleInfo .OwningJiraComponent
94- regenerates , _ := tlsmetadatainterfaces .AnnotationValue (curr .CABundleInfo .SelectedCertMetadataAnnotations , AutoRegenerateAfterOfflineExpiryAnnotation )
47+ regenerates , _ := tlsmetadatainterfaces .AnnotationValue (curr .CABundleInfo .SelectedCertMetadataAnnotations , annotationName )
9548 if len (regenerates ) == 0 {
9649 violatingCABundlesByOwner [owner ] = append (violatingCABundlesByOwner [owner ], curr )
9750 continue
@@ -105,7 +58,7 @@ func generateAutoRegenerateAfterOfflineExpiryshipMarkdown(pkiInfo *certgraphapi.
10558 md .Text ("the cluster will automatically create new cert/key pairs or update CA bundles as required without human" )
10659 md .Text ("intervention." )
10760 md .Textf ("To assert that a particular cert/key pair or CA bundle can do this, add the %q annotation to the secret or configmap and " ,
108- AutoRegenerateAfterOfflineExpiryAnnotation )
61+ annotationName )
10962 md .Text ("setting the value of the annotation a github link to the PR adding the annotation." )
11063 md .Text ("This assertion also means that you have" )
11164 md .OrderedListStart ()
@@ -203,7 +156,3 @@ func generateAutoRegenerateAfterOfflineExpiryshipMarkdown(pkiInfo *certgraphapi.
203156
204157 return md .Bytes (), nil
205158}
206-
207- func (o AutoRegenerateAfterOfflineExpiryRequirement ) GetName () string {
208- return o .name
209- }
0 commit comments