From 1e42aa3aeb6460912143891f12ddf1d436f59974 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Wed, 31 Jul 2024 14:58:47 +0200 Subject: [PATCH] Fix SHH handling Signed-off-by: Carlos Eduardo Arango Gutierrez --- action.yml | 4 ++-- cmd/action/ci/provider.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 4013f44dd..82aaed31f 100644 --- a/action.yml +++ b/action.yml @@ -24,10 +24,10 @@ runs: inputs: aws_access_key_id: description: 'AWS Access Key ID' - required: true + required: false aws_secret_access_key: description: 'AWS Secret Access Key' - required: true + required: false aws_ssh_key: description: 'AWS SSH Key' required: false diff --git a/cmd/action/ci/provider.go b/cmd/action/ci/provider.go index c70cb5e92..2ebc81f99 100644 --- a/cmd/action/ci/provider.go +++ b/cmd/action/ci/provider.go @@ -59,6 +59,19 @@ func newAwsProvider(log *logger.FunLogger, cfg v1alpha1.Environment) (*aws.Provi } } + // Get AWS_SSH_KEY and write it to a file + sshKey := os.Getenv("AWS_SSH_KEY") + if sshKey == "" { + log.Error(fmt.Errorf("ssh key not provided")) + os.Exit(1) + } + + err := os.WriteFile(sshKeyFile, []byte(sshKey), 0600) + if err != nil { + log.Error(fmt.Errorf("error writing ssh key to file: %s", err)) + os.Exit(1) + } + // Set auth.PrivateKey cfg.Spec.Auth.PrivateKey = sshKeyFile cfg.Spec.Auth.Username = username @@ -84,6 +97,22 @@ func newVsphereProvider(log *logger.FunLogger, cfg v1alpha1.Environment) (*vsphe } } + // Get VSPHERE_SSH_KEY and write it to a file + sshKey := os.Getenv("VSPHERE_SSH_KEY") + if sshKey == "" { + log.Error(fmt.Errorf("ssh key not provided")) + os.Exit(1) + } + + err := os.WriteFile(sshKeyFile, []byte(sshKey), 0600) + if err != nil { + log.Error(fmt.Errorf("error writing ssh key to file: %s", err)) + os.Exit(1) + } + + // Set auth.PrivateKey + cfg.Spec.Auth.PrivateKey = sshKeyFile + // Set env name setCfgName(&cfg)