Skip to content

Commit 50d6165

Browse files
committed
ownership markdowns are special, but all annotation based markdown is the same
1 parent c683847 commit 50d6165

File tree

1 file changed

+60
-10
lines changed
  • pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadata/ownership

1 file changed

+60
-10
lines changed

pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadata/ownership/requirement.go

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,74 @@
11
package ownership
22

33
import (
4+
"encoding/json"
45
"fmt"
56

6-
"github.com/openshift/api/annotations"
77
"github.com/openshift/origin/pkg/cmd/update-tls-artifacts/generate-owners/tlsmetadatainterfaces"
88

99
"github.com/openshift/library-go/pkg/certs/cert-inspection/certgraphapi"
1010
"k8s.io/apimachinery/pkg/util/sets"
1111
)
1212

13-
const annotationName string = annotations.OpenShiftComponent
13+
type OwnerRequirement struct {
14+
name string
15+
}
16+
17+
func NewOwnerRequirement() tlsmetadatainterfaces.Requirement {
18+
return OwnerRequirement{
19+
name: "ownership",
20+
}
21+
}
1422

15-
type OwnerRequirement struct{}
23+
func (o OwnerRequirement) InspectRequirement(rawData []*certgraphapi.PKIList) (tlsmetadatainterfaces.RequirementResult, error) {
24+
pkiInfo, err := tlsmetadatainterfaces.ProcessByLocation(rawData)
25+
if err != nil {
26+
return nil, fmt.Errorf("transforming raw data %v: %w", o.GetName(), err)
27+
}
28+
29+
ownershipJSONBytes, err := json.MarshalIndent(pkiInfo, "", " ")
30+
if err != nil {
31+
return nil, fmt.Errorf("failure marshalling %v.json: %w", o.GetName(), err)
32+
}
33+
markdown, err := generateOwnershipMarkdown(pkiInfo)
34+
if err != nil {
35+
return nil, fmt.Errorf("failure marshalling %v.md: %w", o.GetName(), err)
36+
}
37+
violations := generateViolationJSON(pkiInfo)
38+
violationJSONBytes, err := json.MarshalIndent(violations, "", " ")
39+
if err != nil {
40+
return nil, fmt.Errorf("failure marshalling %v-violations.json: %w", o.GetName(), err)
41+
}
1642

17-
func NewOwnerRequirement() tlsmetadatainterfaces.AnnotationRequirement {
18-
return tlsmetadatainterfaces.NewAnnotationRequirement(
19-
"ownership",
20-
annotationName,
21-
generateOwnerMarkdownFn,
22-
)
43+
return tlsmetadatainterfaces.NewRequirementResult(
44+
o.GetName(),
45+
ownershipJSONBytes,
46+
markdown,
47+
violationJSONBytes)
2348
}
2449

25-
func generateOwnerMarkdownFn(pkiInfo *certgraphapi.PKIRegistryInfo) ([]byte, error) {
50+
func generateViolationJSON(pkiInfo *certgraphapi.PKIRegistryInfo) *certgraphapi.PKIRegistryInfo {
51+
ret := &certgraphapi.PKIRegistryInfo{}
52+
53+
for i := range pkiInfo.CertKeyPairs {
54+
curr := pkiInfo.CertKeyPairs[i]
55+
owner := curr.CertKeyInfo.OwningJiraComponent
56+
if len(owner) == 0 || owner == tlsmetadatainterfaces.UnknownOwner {
57+
ret.CertKeyPairs = append(ret.CertKeyPairs, curr)
58+
}
59+
}
60+
for i := range pkiInfo.CertificateAuthorityBundles {
61+
curr := pkiInfo.CertificateAuthorityBundles[i]
62+
owner := curr.CABundleInfo.OwningJiraComponent
63+
if len(owner) == 0 || owner == tlsmetadatainterfaces.UnknownOwner {
64+
ret.CertificateAuthorityBundles = append(ret.CertificateAuthorityBundles, curr)
65+
}
66+
}
67+
68+
return ret
69+
}
70+
71+
func generateOwnershipMarkdown(pkiInfo *certgraphapi.PKIRegistryInfo) ([]byte, error) {
2672
certsByOwner := map[string][]certgraphapi.PKIRegistryInClusterCertKeyPair{}
2773
certsWithoutOwners := []certgraphapi.PKIRegistryInClusterCertKeyPair{}
2874
caBundlesByOwner := map[string][]certgraphapi.PKIRegistryInClusterCABundle{}
@@ -112,3 +158,7 @@ func generateOwnerMarkdownFn(pkiInfo *certgraphapi.PKIRegistryInfo) ([]byte, err
112158

113159
return md.Bytes(), nil
114160
}
161+
162+
func (o OwnerRequirement) GetName() string {
163+
return o.name
164+
}

0 commit comments

Comments
 (0)