Skip to content

Commit 84ec6af

Browse files
Merge pull request #1283 from Roming22/feat/tas-integration
feat: Add the integration command for TAS
2 parents e68fb7a + 4f36f9c commit 84ec6af

File tree

7 files changed

+197
-22
lines changed

7 files changed

+197
-22
lines changed

installer/charts/tssc-dh/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ version: "1.7.0"
66
appVersion: "1.7"
77
annotations:
88
tssc.redhat-appstudio.github.com/product-name: Developer Hub
9-
tssc.redhat-appstudio.github.com/depends-on: tssc-openshift, tssc-subscriptions, tssc-infrastructure, tssc-gitops, tssc-tas, tssc-pipelines, tssc-tpa, tssc-app-namespaces
9+
tssc.redhat-appstudio.github.com/depends-on: tssc-openshift, tssc-subscriptions, tssc-infrastructure, tssc-gitops, tssc-pipelines, tssc-app-namespaces
1010
tssc.redhat-appstudio.github.com/integrations-required: "(bitbucket || github || gitlab) && (artifactory || nexus || quay)"

installer/charts/tssc-pipelines/Chart.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ version: "1.7.0"
77
appVersion: "1.19"
88
annotations:
99
tssc.redhat-appstudio.github.com/product-name: OpenShift Pipelines
10-
tssc.redhat-appstudio.github.com/depends-on: tssc-openshift, tssc-subscriptions, tssc-tas
10+
tssc.redhat-appstudio.github.com/depends-on: tssc-openshift, tssc-subscriptions
11+
tssc.redhat-appstudio.github.com/integrations-required: tas

installer/charts/tssc-tas/Chart.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ appVersion: "1.2"
88
annotations:
99
tssc.redhat-appstudio.github.com/product-name: Trusted Artifact Signer
1010
tssc.redhat-appstudio.github.com/depends-on: tssc-openshift, tssc-subscriptions, tssc-infrastructure, tssc-iam
11+
tssc.redhat-appstudio.github.com/integrations-provided: tas

pkg/integration/tas.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package integration
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log/slog"
7+
8+
"github.com/redhat-appstudio/tssc-cli/pkg/config"
9+
10+
"github.com/spf13/cobra"
11+
corev1 "k8s.io/api/core/v1"
12+
)
13+
14+
// TrustedArtifactSigner represents the coordinates to connect to
15+
// the TrustedArtifactSigner services.
16+
type TrustedArtifactSigner struct {
17+
rekorURL string // URL of the rekor server
18+
tufURL string // URL of the TUF server
19+
}
20+
21+
var _ Interface = &TrustedArtifactSigner{}
22+
23+
// PersistentFlags adds the persistent flags to the informed Cobra command.
24+
func (t *TrustedArtifactSigner) PersistentFlags(c *cobra.Command) {
25+
p := c.PersistentFlags()
26+
27+
p.StringVar(&t.rekorURL, "rekor-url", t.rekorURL,
28+
"URL of the rekor server "+
29+
"(e.g. https://rekor.sigstore.dev)")
30+
p.StringVar(&t.tufURL, "tuf-url", t.tufURL,
31+
"URL of the TUF server "+
32+
"(e.g. https://tuf.trustification.dev)")
33+
34+
for _, f := range []string{
35+
"rekor-url",
36+
"tuf-url",
37+
} {
38+
if err := c.MarkPersistentFlagRequired(f); err != nil {
39+
panic(err)
40+
}
41+
}
42+
}
43+
44+
// SetArgument sets additional arguments to the integration.
45+
func (t *TrustedArtifactSigner) SetArgument(string, string) error {
46+
return nil
47+
}
48+
49+
// LoggerWith decorates the logger with the integration flags.
50+
func (t *TrustedArtifactSigner) LoggerWith(logger *slog.Logger) *slog.Logger {
51+
return logger.With(
52+
"rekor-url", t.rekorURL,
53+
"tuf-url", t.tufURL,
54+
)
55+
}
56+
57+
// Type shares the Kubernetes secret type for this integration.
58+
func (t *TrustedArtifactSigner) Type() corev1.SecretType {
59+
return corev1.SecretTypeOpaque
60+
}
61+
62+
// Validate checks the informed URLs ensure valid inputs.
63+
func (t *TrustedArtifactSigner) Validate() error {
64+
if t.rekorURL == "" {
65+
return fmt.Errorf("rekor-url is required")
66+
}
67+
var err error
68+
if err = ValidateURL(t.rekorURL); err != nil {
69+
return fmt.Errorf("%s: %q", err, t.rekorURL)
70+
}
71+
if t.tufURL == "" {
72+
return fmt.Errorf("tuf-url is required")
73+
}
74+
if err = ValidateURL(t.tufURL); err != nil {
75+
return fmt.Errorf("%s: %q", err, t.tufURL)
76+
}
77+
return nil
78+
}
79+
80+
// Data returns the Kubernetes secret data for this integration.
81+
func (t *TrustedArtifactSigner) Data(
82+
_ context.Context,
83+
_ *config.Config,
84+
) (map[string][]byte, error) {
85+
return map[string][]byte{
86+
"rekor_url": []byte(t.rekorURL),
87+
"tuf_url": []byte(t.tufURL),
88+
}, nil
89+
}
90+
91+
// NewTrustedArtifactSigner creates a new instance of the TrustedArtifactSigner integration.
92+
func NewTrustedArtifactSigner() *TrustedArtifactSigner {
93+
return &TrustedArtifactSigner{}
94+
}

pkg/integrations/manager.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ type Manager struct {
2222
}
2323

2424
const (
25-
ACS IntegrationName = "acs"
26-
Artifactory IntegrationName = "artifactory"
27-
Azure IntegrationName = "azure"
28-
BitBucket IntegrationName = "bitbucket"
29-
GitHub IntegrationName = "github"
30-
GitLab IntegrationName = "gitlab"
31-
Jenkins IntegrationName = "jenkins"
32-
Nexus IntegrationName = "nexus"
33-
Quay IntegrationName = "quay"
34-
Trustification IntegrationName = "trustification"
25+
ACS IntegrationName = "acs"
26+
Artifactory IntegrationName = "artifactory"
27+
Azure IntegrationName = "azure"
28+
BitBucket IntegrationName = "bitbucket"
29+
GitHub IntegrationName = "github"
30+
GitLab IntegrationName = "gitlab"
31+
Jenkins IntegrationName = "jenkins"
32+
Nexus IntegrationName = "nexus"
33+
Quay IntegrationName = "quay"
34+
TrustedArtifactSigner IntegrationName = "tas"
35+
Trustification IntegrationName = "trustification"
3536
)
3637

3738
// Integration returns the integration instance by name.
@@ -76,16 +77,17 @@ func NewManager(logger *slog.Logger, kube *k8s.Kube) *Manager {
7677
// Instantiating all integrations making sure the set of integrations is
7778
// complete and unique. The application must panic on duplicated integrations.
7879
for name, data := range map[IntegrationName]integration.Interface{
79-
ACS: integration.NewACS(),
80-
Artifactory: integration.NewContainerRegistry(""),
81-
Azure: integration.NewAzure(),
82-
BitBucket: integration.NewBitBucket(),
83-
GitHub: integration.NewGitHub(logger, kube),
84-
GitLab: integration.NewGitLab(logger),
85-
Jenkins: integration.NewJenkins(),
86-
Nexus: integration.NewContainerRegistry(""),
87-
Quay: integration.NewContainerRegistry(integration.QuayURL),
88-
Trustification: integration.NewTrustification(),
80+
ACS: integration.NewACS(),
81+
Artifactory: integration.NewContainerRegistry(""),
82+
Azure: integration.NewAzure(),
83+
BitBucket: integration.NewBitBucket(),
84+
GitHub: integration.NewGitHub(logger, kube),
85+
GitLab: integration.NewGitLab(logger),
86+
Jenkins: integration.NewJenkins(),
87+
Nexus: integration.NewContainerRegistry(""),
88+
Quay: integration.NewContainerRegistry(integration.QuayURL),
89+
TrustedArtifactSigner: integration.NewTrustedArtifactSigner(),
90+
Trustification: integration.NewTrustification(),
8991
} {
9092
// Ensure unique integration names.
9193
if _, exists := m.integrations[name]; exists {

pkg/subcmd/integration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func NewIntegration(logger *slog.Logger, kube *k8s.Kube) *cobra.Command {
3636
logger, kube, manager.Integration(integrations.Nexus)),
3737
NewIntegrationQuay(
3838
logger, kube, manager.Integration(integrations.Quay)),
39+
NewIntegrationTrustedArtifactSigner(
40+
logger, kube, manager.Integration(integrations.TrustedArtifactSigner)),
3941
NewIntegrationTrustification(
4042
logger, kube, manager.Integration(integrations.Trustification)),
4143
} {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package subcmd
2+
3+
import (
4+
"log/slog"
5+
6+
"github.com/redhat-appstudio/tssc-cli/pkg/config"
7+
"github.com/redhat-appstudio/tssc-cli/pkg/integration"
8+
"github.com/redhat-appstudio/tssc-cli/pkg/k8s"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// IntegrationTrustedArtifactSigner is the sub-command for the "integration trusted-artifact-signer",
14+
// responsible for creating and updating the TrustedArtifactSigner integration secret.
15+
type IntegrationTrustedArtifactSigner struct {
16+
cmd *cobra.Command // cobra command
17+
logger *slog.Logger // application logger
18+
cfg *config.Config // installer configuration
19+
kube *k8s.Kube // kubernetes client
20+
integration *integration.Integration // integration instance
21+
}
22+
23+
var _ Interface = &IntegrationTrustedArtifactSigner{}
24+
25+
const trustedArtifactSignerIntegrationLongDesc = `
26+
Manages the TrustedArtifactSigner integration with TSSC, by storing the required
27+
URL required to interact with Trusted Artifact Signer.
28+
29+
The credentials are stored in a Kubernetes Secret in the configured namespace for TSSC.`
30+
31+
// Cmd exposes the cobra instance.
32+
func (t *IntegrationTrustedArtifactSigner) Cmd() *cobra.Command {
33+
return t.cmd
34+
}
35+
36+
// Complete is a no-op in this case.
37+
func (t *IntegrationTrustedArtifactSigner) Complete(args []string) error {
38+
var err error
39+
t.cfg, err = bootstrapConfig(t.cmd.Context(), t.kube)
40+
return err
41+
}
42+
43+
// Validate checks if the required configuration is set.
44+
func (t *IntegrationTrustedArtifactSigner) Validate() error {
45+
return t.integration.Validate()
46+
}
47+
48+
// Run creates or updates the TrustedArtifactSigner integration secret.
49+
func (t *IntegrationTrustedArtifactSigner) Run() error {
50+
return t.integration.Create(t.cmd.Context(), t.cfg)
51+
}
52+
53+
// NewIntegrationTrustedArtifactSigner creates the sub-command for the "integration
54+
// trusted-artifact-signer" responsible to manage the TSSC integrations with the
55+
// Trusted Artifact Signer services.
56+
func NewIntegrationTrustedArtifactSigner(
57+
logger *slog.Logger,
58+
kube *k8s.Kube,
59+
i *integration.Integration,
60+
) *IntegrationTrustedArtifactSigner {
61+
t := &IntegrationTrustedArtifactSigner{
62+
cmd: &cobra.Command{
63+
Use: "trusted-artifact-signer [flags]",
64+
Short: "Integrates a Trusted Artifact Signer instance into TSSC",
65+
Long: trustedArtifactSignerIntegrationLongDesc,
66+
SilenceUsage: true,
67+
},
68+
69+
logger: logger,
70+
kube: kube,
71+
integration: i,
72+
}
73+
i.PersistentFlags(t.cmd)
74+
return t
75+
}

0 commit comments

Comments
 (0)