Skip to content

Commit 6147d8a

Browse files
committed
feat: ssh credentials
1 parent cf13d93 commit 6147d8a

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

cmd/deploy_flux.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ var deployFluxCmd = &cobra.Command{
2222
Use: "deploy-flux source target",
2323
Short: "Transfer an OCM component from a source to a target location",
2424
Long: `Transfers the specified OCM component version from the source location to the target location.`,
25-
Args: cobra.ExactArgs(4),
25+
Args: cobra.ExactArgs(5),
2626
ArgAliases: []string{
2727
"component-location",
2828
"deployment-templates",
2929
"deployment-repository",
3030
"deployment-repository-branch",
31+
"deployment-repository-path",
3132
},
3233
RunE: func(cmd *cobra.Command, args []string) error {
3334
log := logging.GetLogger()
3435
log.Debugf("Executing deploy-flux with component-location: %s, deployment-templates: %s, "+
35-
"deployment-repository: %s, deployment-repository-branch: %s",
36-
args[0], args[1], args[2], args[3])
36+
"deployment-repository: %s, deployment-repository-branch: %s, deployment-repository-path: %s",
37+
args[0], args[1], args[2], args[3], args[4])
3738

3839
platformKubeconfig := cmd.Flag(flagKubeconfig).Value.String()
3940
platformCluster := clusters.New("platform").WithConfigPath(platformKubeconfig)
@@ -44,7 +45,7 @@ var deployFluxCmd = &cobra.Command{
4445
return fmt.Errorf("error initializing client for platform cluster: %w", err)
4546
}
4647

47-
d := flux_deployer.NewFluxDeployer(args[0], args[1], args[2], args[3],
48+
d := flux_deployer.NewFluxDeployer(args[0], args[1], args[2], args[3], args[4],
4849
cmd.Flag(flagOCMConfig).Value.String(),
4950
cmd.Flag(flagGitCredentials).Value.String(),
5051
cmd.Flag(flagFluxCDNamespace).Value.String(),

internal/flux_deployer/deployer.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type FluxDeployer struct {
2929
deploymentTemplates string
3030
deploymentRepository string
3131
deploymentRepositoryBranch string
32+
deploymentRepositoryPath string
3233
ocmConfig string
3334
gitCredentials string
3435
fluxcdNamespace string
@@ -37,14 +38,15 @@ type FluxDeployer struct {
3738
log *logrus.Logger
3839
}
3940

40-
func NewFluxDeployer(componentLocation, deploymentTemplates, deploymentRepository, deploymentRepositoryBranch,
41+
func NewFluxDeployer(componentLocation, deploymentTemplates, deploymentRepository, deploymentRepositoryBranch, deploymentRepositoryPath,
4142
ocmConfig, gitCredentials, fluxcdNamespace, platformKubeconfig string, platformCluster *clusters.Cluster, log *logrus.Logger) *FluxDeployer {
4243

4344
return &FluxDeployer{
4445
componentLocation: componentLocation,
4546
deploymentTemplates: deploymentTemplates,
4647
deploymentRepository: deploymentRepository,
4748
deploymentRepositoryBranch: deploymentRepositoryBranch,
49+
deploymentRepositoryPath: deploymentRepositoryPath,
4850
ocmConfig: ocmConfig,
4951
gitCredentials: gitCredentials,
5052
fluxcdNamespace: fluxcdNamespace,
@@ -139,16 +141,13 @@ func (d *FluxDeployer) establishFluxSync(ctx context.Context, downloadDir string
139141
}
140142

141143
// Template
142-
// TODO: further parameters:
143-
// - spec.secretRef.name in the GitRepository: spec.secretRef.name
144-
// - spec.path in the Kustomization
145144
values := map[string]any{
146145
"Values": map[string]any{
147146
"namespace": d.fluxcdNamespace,
148147
"git": map[string]any{
149148
"repoUrl": d.deploymentRepository,
150149
"mainBranch": d.deploymentRepositoryBranch,
151-
"path": "provider",
150+
"path": d.deploymentRepositoryPath,
152151
"secretName": secretName,
153152
},
154153
},

internal/flux_deployer/git_credentials.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package flux_deployer
22

33
import (
44
"context"
5+
"encoding/base64"
56
"fmt"
67
"os"
78

@@ -52,7 +53,12 @@ func CreateGitCredentialsSecret(ctx context.Context, gitCredentials string, secr
5253
gitCredentialsData[token] = config.Authentication.BearerToken.Token
5354
}
5455
if config.Authentication.SSHPrivateKey != nil {
55-
gitCredentialsData[identity] = config.Authentication.SSHPrivateKey.PrivateKey
56+
privateKey, err := base64.StdEncoding.DecodeString(config.Authentication.SSHPrivateKey.PrivateKey)
57+
if err != nil {
58+
return fmt.Errorf("error base64 decoding SSH private key: %w", err)
59+
}
60+
61+
gitCredentialsData[identity] = string(privateKey)
5662

5763
if config.Authentication.SSHPrivateKey.KnownHosts != "" {
5864
knownHostsPath := config.Authentication.SSHPrivateKey.KnownHosts

0 commit comments

Comments
 (0)