From 6921cf5913e2c921f16771b7cbd231393daa8b2f Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 17 Oct 2023 18:46:20 +0545 Subject: [PATCH 1/7] feat: add support for env vars in exec check --- api/v1/checks.go | 12 +++ api/v1/zz_generated.deepcopy.go | 30 ++++++ checks/exec.go | 61 ++++++++---- config/deploy/crd.yaml | 123 +++++++++++++++++++++++++ config/schemas/canary.schema.json | 30 ++++++ config/schemas/component.schema.json | 30 ++++++ config/schemas/health_exec.schema.json | 30 ++++++ config/schemas/topology.schema.json | 30 ++++++ fixtures/minimal/exec_env.yaml | 18 ++++ 9 files changed, 345 insertions(+), 19 deletions(-) create mode 100644 fixtures/minimal/exec_env.yaml diff --git a/api/v1/checks.go b/api/v1/checks.go index 5e4db0a0c..1025a6f17 100644 --- a/api/v1/checks.go +++ b/api/v1/checks.go @@ -968,6 +968,14 @@ type ExecConnections struct { Azure *AzureConnection `yaml:"azure,omitempty" json:"azure,omitempty"` } +type GitCheckout struct { + URL string `yaml:"url,omitempty" json:"url,omitempty"` + Connection string `yaml:"connection,omitempty" json:"connection,omitempty"` + Username types.EnvVar `yaml:"username,omitempty" json:"username,omitempty"` + Password types.EnvVar `yaml:"password,omitempty" json:"password,omitempty"` + Certificate types.EnvVar `yaml:"certificate,omitempty" json:"certificate,omitempty"` +} + type ExecCheck struct { Description `yaml:",inline" json:",inline"` Templatable `yaml:",inline" json:",inline"` @@ -975,6 +983,10 @@ type ExecCheck struct { // On windows executed via powershell and in darwin and linux executed using bash Script string `yaml:"script" json:"script"` Connections ExecConnections `yaml:"connections,omitempty" json:"connections,omitempty"` + // EnvVars are the environment variables that are accesible to exec processes + EnvVars []types.EnvVar `yaml:"env,omitempty" json:"env,omitempty"` + // Checkout details the git repository that should be mounted to the process + Checkout *GitCheckout `yaml:"checkout,omitempty" json:"checkout,omitempty"` } func (c ExecCheck) GetType() string { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index aa828e78e..cbfaf3448 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1600,6 +1600,18 @@ func (in *ExecCheck) DeepCopyInto(out *ExecCheck) { in.Description.DeepCopyInto(&out.Description) out.Templatable = in.Templatable in.Connections.DeepCopyInto(&out.Connections) + if in.EnvVars != nil { + in, out := &in.EnvVars, &out.EnvVars + *out = make([]types.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Checkout != nil { + in, out := &in.Checkout, &out.Checkout + *out = new(GitCheckout) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExecCheck. @@ -1846,6 +1858,24 @@ func (in *Git) DeepCopy() *Git { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GitCheckout) DeepCopyInto(out *GitCheckout) { + *out = *in + in.Username.DeepCopyInto(&out.Username) + in.Password.DeepCopyInto(&out.Password) + in.Certificate.DeepCopyInto(&out.Certificate) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitCheckout. +func (in *GitCheckout) DeepCopy() *GitCheckout { + if in == nil { + return nil + } + out := new(GitCheckout) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GitHubCheck) DeepCopyInto(out *GitHubCheck) { *out = *in diff --git a/checks/exec.go b/checks/exec.go index 3da78efcd..884ad671b 100644 --- a/checks/exec.go +++ b/checks/exec.go @@ -16,6 +16,7 @@ import ( v1 "github.com/flanksource/canary-checker/api/v1" "github.com/flanksource/canary-checker/pkg" "github.com/flanksource/commons/logger" + "github.com/flanksource/duty/types" ) type ExecChecker struct { @@ -36,27 +37,55 @@ func (c *ExecChecker) Run(ctx *context.Context) pkg.Results { for _, conf := range ctx.Canary.Spec.Exec { results = append(results, c.Check(ctx, conf)...) } + return results } func (c *ExecChecker) Check(ctx *context.Context, extConfig external.Check) pkg.Results { check := extConfig.(v1.ExecCheck) + for i, env := range check.EnvVars { + val, err := ctx.GetEnvValueFromCache(env) + if err != nil { + return []*pkg.CheckResult{pkg.Fail(check, ctx.Canary).Failf("error fetching env value (name=%s): %v", env.Name, err)} + } + + check.EnvVars[i].ValueStatic = val + } + switch runtime.GOOS { case "windows": - return execPowershell(check, ctx) + return execPowershell(ctx, check) default: - return execBash(check, ctx) + return execBash(ctx, check) } } -func execPowershell(check v1.ExecCheck, ctx *context.Context) pkg.Results { +func execPowershell(ctx *context.Context, check v1.ExecCheck) pkg.Results { result := pkg.Success(check, ctx.Canary) ps, err := osExec.LookPath("powershell.exe") if err != nil { result.Failf("powershell not found") } + args := []string{check.Script} - cmd := osExec.Command(ps, args...) + cmd := osExec.CommandContext(ctx, ps, args...) + cmd.Env = append(os.Environ(), envVarSlice(check.EnvVars)...) + return runCmd(cmd, result) +} + +func execBash(ctx *context.Context, check v1.ExecCheck) pkg.Results { + result := pkg.Success(check, ctx.Canary) + fields := strings.Fields(check.Script) + if len(fields) == 0 { + return []*pkg.CheckResult{result.Failf("no script provided")} + } + + cmd := osExec.CommandContext(ctx, "bash", "-c", check.Script) + cmd.Env = append(os.Environ(), envVarSlice(check.EnvVars)...) + if err := setupConnection(ctx, check, cmd); err != nil { + return []*pkg.CheckResult{result.Failf("failed to setup connection: %v", err)} + } + return runCmd(cmd, result) } @@ -117,21 +146,6 @@ func setupConnection(ctx *context.Context, check v1.ExecCheck, cmd *osExec.Cmd) return nil } -func execBash(check v1.ExecCheck, ctx *context.Context) pkg.Results { - result := pkg.Success(check, ctx.Canary) - fields := strings.Fields(check.Script) - if len(fields) == 0 { - return []*pkg.CheckResult{result.Failf("no script provided")} - } - - cmd := osExec.Command("bash", "-c", check.Script) - if err := setupConnection(ctx, check, cmd); err != nil { - return []*pkg.CheckResult{result.Failf("failed to setup connection: %v", err)} - } - - return runCmd(cmd, result) -} - func runCmd(cmd *osExec.Cmd, result *pkg.CheckResult) (results pkg.Results) { var stdout bytes.Buffer var stderr bytes.Buffer @@ -174,6 +188,15 @@ func saveConfig(configTemplate *textTemplate.Template, view any) (string, error) return configPath, nil } +func envVarSlice(envs []types.EnvVar) []string { + result := make([]string, len(envs)) + for i, env := range envs { + result[i] = fmt.Sprintf("%s=%s", env.Name, env.ValueStatic) + } + + return result +} + var ( awsConfigTemplate *textTemplate.Template gcloudConfigTemplate *textTemplate.Template diff --git a/config/deploy/crd.yaml b/config/deploy/crd.yaml index 8211b31c5..eac1232e7 100644 --- a/config/deploy/crd.yaml +++ b/config/deploy/crd.yaml @@ -2105,6 +2105,98 @@ spec: exec: items: properties: + checkout: + description: Checkout details the git repository that should be mounted to the process + properties: + certificate: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + connection: + type: string + password: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + url: + type: string + username: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + type: object connections: properties: aws: @@ -2324,6 +2416,37 @@ spec: template: type: string type: object + env: + description: EnvVars are the environment variables that are accesible to exec processes + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + type: array icon: description: Icon for overwriting default icon on the dashboard type: string diff --git a/config/schemas/canary.schema.json b/config/schemas/canary.schema.json index f380d963e..660b42ec4 100644 --- a/config/schemas/canary.schema.json +++ b/config/schemas/canary.schema.json @@ -1394,6 +1394,15 @@ }, "connections": { "$ref": "#/$defs/ExecConnections" + }, + "env": { + "items": { + "$ref": "#/$defs/EnvVar" + }, + "type": "array" + }, + "checkout": { + "$ref": "#/$defs/GitCheckout" } }, "additionalProperties": false, @@ -1560,6 +1569,27 @@ "instance" ] }, + "GitCheckout": { + "properties": { + "url": { + "type": "string" + }, + "connection": { + "type": "string" + }, + "username": { + "$ref": "#/$defs/EnvVar" + }, + "password": { + "$ref": "#/$defs/EnvVar" + }, + "certificate": { + "$ref": "#/$defs/EnvVar" + } + }, + "additionalProperties": false, + "type": "object" + }, "GitHubCheck": { "properties": { "description": { diff --git a/config/schemas/component.schema.json b/config/schemas/component.schema.json index c5f40cf4f..791c2e90c 100644 --- a/config/schemas/component.schema.json +++ b/config/schemas/component.schema.json @@ -1573,6 +1573,15 @@ }, "connections": { "$ref": "#/$defs/ExecConnections" + }, + "env": { + "items": { + "$ref": "#/$defs/EnvVar" + }, + "type": "array" + }, + "checkout": { + "$ref": "#/$defs/GitCheckout" } }, "additionalProperties": false, @@ -1772,6 +1781,27 @@ "instance" ] }, + "GitCheckout": { + "properties": { + "url": { + "type": "string" + }, + "connection": { + "type": "string" + }, + "username": { + "$ref": "#/$defs/EnvVar" + }, + "password": { + "$ref": "#/$defs/EnvVar" + }, + "certificate": { + "$ref": "#/$defs/EnvVar" + } + }, + "additionalProperties": false, + "type": "object" + }, "GitHubCheck": { "properties": { "description": { diff --git a/config/schemas/health_exec.schema.json b/config/schemas/health_exec.schema.json index afe65cfc6..a70644733 100644 --- a/config/schemas/health_exec.schema.json +++ b/config/schemas/health_exec.schema.json @@ -133,6 +133,15 @@ }, "connections": { "$ref": "#/$defs/ExecConnections" + }, + "env": { + "items": { + "$ref": "#/$defs/EnvVar" + }, + "type": "array" + }, + "checkout": { + "$ref": "#/$defs/GitCheckout" } }, "additionalProperties": false, @@ -172,6 +181,27 @@ "additionalProperties": false, "type": "object" }, + "GitCheckout": { + "properties": { + "url": { + "type": "string" + }, + "connection": { + "type": "string" + }, + "username": { + "$ref": "#/$defs/EnvVar" + }, + "password": { + "$ref": "#/$defs/EnvVar" + }, + "certificate": { + "$ref": "#/$defs/EnvVar" + } + }, + "additionalProperties": false, + "type": "object" + }, "Labels": { "patternProperties": { ".*": { diff --git a/config/schemas/topology.schema.json b/config/schemas/topology.schema.json index dca59a7db..2460b6d40 100644 --- a/config/schemas/topology.schema.json +++ b/config/schemas/topology.schema.json @@ -1543,6 +1543,15 @@ }, "connections": { "$ref": "#/$defs/ExecConnections" + }, + "env": { + "items": { + "$ref": "#/$defs/EnvVar" + }, + "type": "array" + }, + "checkout": { + "$ref": "#/$defs/GitCheckout" } }, "additionalProperties": false, @@ -1742,6 +1751,27 @@ "instance" ] }, + "GitCheckout": { + "properties": { + "url": { + "type": "string" + }, + "connection": { + "type": "string" + }, + "username": { + "$ref": "#/$defs/EnvVar" + }, + "password": { + "$ref": "#/$defs/EnvVar" + }, + "certificate": { + "$ref": "#/$defs/EnvVar" + } + }, + "additionalProperties": false, + "type": "object" + }, "GitHubCheck": { "properties": { "description": { diff --git a/fixtures/minimal/exec_env.yaml b/fixtures/minimal/exec_env.yaml new file mode 100644 index 000000000..7f3f33fc0 --- /dev/null +++ b/fixtures/minimal/exec_env.yaml @@ -0,0 +1,18 @@ +apiVersion: canaries.flanksource.com/v1 +kind: Canary +metadata: + name: exec-env +spec: + interval: 30 + exec: + - name: exec-env + description: "exec with env" + script: | + echo -n ${FL_HELLO} ${FL_WORLD} + env: + - name: FL_HELLO + value: "hello" + - name: FL_WORLD + value: "world" + test: + expr: 'results.stdout == "hello world"' From deb6f30ca29a8dd6e82d12313a22142cb44ef410 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Tue, 17 Oct 2023 19:48:35 +0545 Subject: [PATCH 2/7] feat: impl checkout on exec action --- .gitignore | 1 + api/v1/checks.go | 3 + checks/exec.go | 85 ++++++++++++----- config/deploy/crd.yaml | 3 + config/deploy/manifests.yaml | 126 +++++++++++++++++++++++++ config/schemas/canary.schema.json | 3 + config/schemas/component.schema.json | 3 + config/schemas/health_exec.schema.json | 3 + config/schemas/topology.schema.json | 3 + fixtures/minimal/exec_checkout.yaml | 15 +++ 10 files changed, 224 insertions(+), 21 deletions(-) create mode 100644 fixtures/minimal/exec_checkout.yaml diff --git a/.gitignore b/.gitignore index 289b82f42..a7bd0b67f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ postgres-db/ ui/scripts/ Chart.lock chart/charts/ +.downloads diff --git a/api/v1/checks.go b/api/v1/checks.go index 1025a6f17..df5042558 100644 --- a/api/v1/checks.go +++ b/api/v1/checks.go @@ -974,6 +974,9 @@ type GitCheckout struct { Username types.EnvVar `yaml:"username,omitempty" json:"username,omitempty"` Password types.EnvVar `yaml:"password,omitempty" json:"password,omitempty"` Certificate types.EnvVar `yaml:"certificate,omitempty" json:"certificate,omitempty"` + // Destination is the full path to where the contents of the URL should be downloaded to. + // If left empty, the sha256 hash of the URL will be used as the dir name. + Destination string `yaml:"destination,omitempty" json:"destination,omitempty"` } type ExecCheck struct { diff --git a/checks/exec.go b/checks/exec.go index 884ad671b..89371fba1 100644 --- a/checks/exec.go +++ b/checks/exec.go @@ -15,8 +15,9 @@ import ( "github.com/flanksource/canary-checker/api/external" v1 "github.com/flanksource/canary-checker/api/v1" "github.com/flanksource/canary-checker/pkg" + "github.com/flanksource/commons/files" + "github.com/flanksource/commons/hash" "github.com/flanksource/commons/logger" - "github.com/flanksource/duty/types" ) type ExecChecker struct { @@ -41,26 +42,65 @@ func (c *ExecChecker) Run(ctx *context.Context) pkg.Results { return results } -func (c *ExecChecker) Check(ctx *context.Context, extConfig external.Check) pkg.Results { - check := extConfig.(v1.ExecCheck) - for i, env := range check.EnvVars { +type execEnv struct { + envs []string + mountPoint string +} + +func (c *ExecChecker) prepareEnvironment(ctx *context.Context, check v1.ExecCheck) (*execEnv, error) { + var result execEnv + + for _, env := range check.EnvVars { val, err := ctx.GetEnvValueFromCache(env) if err != nil { - return []*pkg.CheckResult{pkg.Fail(check, ctx.Canary).Failf("error fetching env value (name=%s): %v", env.Name, err)} + return nil, fmt.Errorf("error fetching env value (name=%s): %w", env.Name, err) + } + + result.envs = append(result.envs, fmt.Sprintf("%s=%s", env.Name, val)) + } + + if check.Checkout != nil { + if connection, err := ctx.HydrateConnectionByURL(check.Checkout.Connection); err != nil { + return nil, fmt.Errorf("error hydrating connection: %w", err) + } else if connection != nil { + check.Checkout.URL = connection.URL + } + + if check.Checkout.URL == "" { + return nil, fmt.Errorf("error checking out. missing URL") + } + + result.mountPoint = check.Checkout.Destination + if check.Checkout.Destination == "" { + pwd, _ := os.Getwd() + result.mountPoint = filepath.Join(pwd, ".downloads", hash.Sha256Hex(check.Checkout.URL)) + } + + if err := files.Getter(check.Checkout.URL, result.mountPoint); err != nil { + return nil, fmt.Errorf("error checking out %s: %w", check.Checkout.URL, err) } + } - check.EnvVars[i].ValueStatic = val + return &result, nil +} + +func (c *ExecChecker) Check(ctx *context.Context, extConfig external.Check) pkg.Results { + check := extConfig.(v1.ExecCheck) + + env, err := c.prepareEnvironment(ctx, check) + if err != nil { + return []*pkg.CheckResult{pkg.Fail(check, ctx.Canary).Failf("something went wrong while preparing exec env: %v", err)} } switch runtime.GOOS { case "windows": - return execPowershell(ctx, check) + return execPowershell(ctx, check, env) default: - return execBash(ctx, check) + return execBash(ctx, check, env) } } -func execPowershell(ctx *context.Context, check v1.ExecCheck) pkg.Results { +func execPowershell(ctx *context.Context, check v1.ExecCheck, envParams *execEnv) pkg.Results { result := pkg.Success(check, ctx.Canary) ps, err := osExec.LookPath("powershell.exe") if err != nil { @@ -69,11 +109,17 @@ func execPowershell(ctx *context.Context, check v1.ExecCheck) pkg.Results { args := []string{check.Script} cmd := osExec.CommandContext(ctx, ps, args...) - cmd.Env = append(os.Environ(), envVarSlice(check.EnvVars)...) + if len(envParams.envs) != 0 { + cmd.Env = append(os.Environ(), envParams.envs...) + } + if envParams.mountPoint != "" { + cmd.Dir = envParams.mountPoint + } + return runCmd(cmd, result) } -func execBash(ctx *context.Context, check v1.ExecCheck) pkg.Results { +func execBash(ctx *context.Context, check v1.ExecCheck, envParams *execEnv) pkg.Results { result := pkg.Success(check, ctx.Canary) fields := strings.Fields(check.Script) if len(fields) == 0 { @@ -81,7 +127,13 @@ func execBash(ctx *context.Context, check v1.ExecCheck) pkg.Results { } cmd := osExec.CommandContext(ctx, "bash", "-c", check.Script) - cmd.Env = append(os.Environ(), envVarSlice(check.EnvVars)...) + if len(envParams.envs) != 0 { + cmd.Env = append(os.Environ(), envParams.envs...) + } + if envParams.mountPoint != "" { + cmd.Dir = envParams.mountPoint + } + if err := setupConnection(ctx, check, cmd); err != nil { return []*pkg.CheckResult{result.Failf("failed to setup connection: %v", err)} } @@ -188,15 +240,6 @@ func saveConfig(configTemplate *textTemplate.Template, view any) (string, error) return configPath, nil } -func envVarSlice(envs []types.EnvVar) []string { - result := make([]string, len(envs)) - for i, env := range envs { - result[i] = fmt.Sprintf("%s=%s", env.Name, env.ValueStatic) - } - - return result -} - var ( awsConfigTemplate *textTemplate.Template gcloudConfigTemplate *textTemplate.Template diff --git a/config/deploy/crd.yaml b/config/deploy/crd.yaml index eac1232e7..73236e103 100644 --- a/config/deploy/crd.yaml +++ b/config/deploy/crd.yaml @@ -2138,6 +2138,9 @@ spec: type: object connection: type: string + destination: + description: Destination is the full path to where the contents of the URL should be downloaded to. If left empty, the sha256 hash of the URL will be used as the dir name. + type: string password: properties: name: diff --git a/config/deploy/manifests.yaml b/config/deploy/manifests.yaml index 228a51f38..9337721d3 100644 --- a/config/deploy/manifests.yaml +++ b/config/deploy/manifests.yaml @@ -2105,6 +2105,101 @@ spec: exec: items: properties: + checkout: + description: Checkout details the git repository that should be mounted to the process + properties: + certificate: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + connection: + type: string + destination: + description: Destination is the full path to where the contents of the URL should be downloaded to. If left empty, the sha256 hash of the URL will be used as the dir name. + type: string + password: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + url: + type: string + username: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + type: object connections: properties: aws: @@ -2324,6 +2419,37 @@ spec: template: type: string type: object + env: + description: EnvVars are the environment variables that are accesible to exec processes + items: + properties: + name: + type: string + value: + type: string + valueFrom: + properties: + configMapKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + secretKeyRef: + properties: + key: + type: string + name: + type: string + required: + - key + type: object + type: object + type: object + type: array icon: description: Icon for overwriting default icon on the dashboard type: string diff --git a/config/schemas/canary.schema.json b/config/schemas/canary.schema.json index 660b42ec4..b40faea98 100644 --- a/config/schemas/canary.schema.json +++ b/config/schemas/canary.schema.json @@ -1585,6 +1585,9 @@ }, "certificate": { "$ref": "#/$defs/EnvVar" + }, + "destination": { + "type": "string" } }, "additionalProperties": false, diff --git a/config/schemas/component.schema.json b/config/schemas/component.schema.json index 791c2e90c..be7245517 100644 --- a/config/schemas/component.schema.json +++ b/config/schemas/component.schema.json @@ -1797,6 +1797,9 @@ }, "certificate": { "$ref": "#/$defs/EnvVar" + }, + "destination": { + "type": "string" } }, "additionalProperties": false, diff --git a/config/schemas/health_exec.schema.json b/config/schemas/health_exec.schema.json index a70644733..8e9f4948d 100644 --- a/config/schemas/health_exec.schema.json +++ b/config/schemas/health_exec.schema.json @@ -197,6 +197,9 @@ }, "certificate": { "$ref": "#/$defs/EnvVar" + }, + "destination": { + "type": "string" } }, "additionalProperties": false, diff --git a/config/schemas/topology.schema.json b/config/schemas/topology.schema.json index 2460b6d40..368a4e4ed 100644 --- a/config/schemas/topology.schema.json +++ b/config/schemas/topology.schema.json @@ -1767,6 +1767,9 @@ }, "certificate": { "$ref": "#/$defs/EnvVar" + }, + "destination": { + "type": "string" } }, "additionalProperties": false, diff --git a/fixtures/minimal/exec_checkout.yaml b/fixtures/minimal/exec_checkout.yaml new file mode 100644 index 000000000..344019a6a --- /dev/null +++ b/fixtures/minimal/exec_checkout.yaml @@ -0,0 +1,15 @@ +apiVersion: canaries.flanksource.com/v1 +kind: Canary +metadata: + name: exec-checkout +spec: + interval: 30 + exec: + - name: exec-checkout + description: "exec with git" + script: | + cat go.mod | head -n 1 + checkout: + url: github.com/flanksource/duty + test: + expr: 'results.stdout == "module github.com/flanksource/duty"' From 8694e412867728c5159206aa11708f83121e2113 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 18 Oct 2023 10:14:18 +0545 Subject: [PATCH 3/7] chore: rename fixtures. add _pass suffix --- fixtures/minimal/{exec_checkout.yaml => exec_checkout_pass.yaml} | 0 fixtures/minimal/{exec_env.yaml => exec_env_pass.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename fixtures/minimal/{exec_checkout.yaml => exec_checkout_pass.yaml} (100%) rename fixtures/minimal/{exec_env.yaml => exec_env_pass.yaml} (100%) diff --git a/fixtures/minimal/exec_checkout.yaml b/fixtures/minimal/exec_checkout_pass.yaml similarity index 100% rename from fixtures/minimal/exec_checkout.yaml rename to fixtures/minimal/exec_checkout_pass.yaml diff --git a/fixtures/minimal/exec_env.yaml b/fixtures/minimal/exec_env_pass.yaml similarity index 100% rename from fixtures/minimal/exec_env.yaml rename to fixtures/minimal/exec_env_pass.yaml From 9246822374812749fc2a029b467916e72f5a949b Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Wed, 18 Oct 2023 15:24:13 +0545 Subject: [PATCH 4/7] chore: use connection's AsGoGetterURL --- checks/exec.go | 18 ++++++++++++------ go.mod | 14 ++++++++------ go.sum | 27 +++++++++++++-------------- pkg/jobs/canary/sync_upstream.go | 8 ++++---- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/checks/exec.go b/checks/exec.go index 89371fba1..99a0be963 100644 --- a/checks/exec.go +++ b/checks/exec.go @@ -60,24 +60,30 @@ func (c *ExecChecker) prepareEnvironment(ctx *context.Context, check v1.ExecChec } if check.Checkout != nil { + sourceURL := check.Checkout.URL + if connection, err := ctx.HydrateConnectionByURL(check.Checkout.Connection); err != nil { return nil, fmt.Errorf("error hydrating connection: %w", err) } else if connection != nil { - check.Checkout.URL = connection.URL + goGetterURL, err := connection.AsGoGetterURL() + if err != nil { + return nil, fmt.Errorf("error getting go getter URL: %w", err) + } + sourceURL = goGetterURL } - if check.Checkout.URL == "" { + if sourceURL == "" { return nil, fmt.Errorf("error checking out. missing URL") } result.mountPoint = check.Checkout.Destination - if check.Checkout.Destination == "" { + if result.mountPoint == "" { pwd, _ := os.Getwd() - result.mountPoint = filepath.Join(pwd, ".downloads", hash.Sha256Hex(check.Checkout.URL)) + result.mountPoint = filepath.Join(pwd, ".downloads", hash.Sha256Hex(sourceURL)) } - if err := files.Getter(check.Checkout.URL, result.mountPoint); err != nil { - return nil, fmt.Errorf("error checking out %s: %w", check.Checkout.URL, err) + if err := files.Getter(sourceURL, result.mountPoint); err != nil { + return nil, fmt.Errorf("error checking out %s: %w", sourceURL, err) } } diff --git a/go.mod b/go.mod index 4598e39e3..e3af46466 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/eko/gocache/store/bigcache/v4 v4.2.1 github.com/elastic/go-elasticsearch/v8 v8.10.0 github.com/fergusstrange/embedded-postgres v1.24.0 - github.com/flanksource/commons v1.15.0 + github.com/flanksource/commons v1.15.1 github.com/flanksource/duty v1.0.191 github.com/flanksource/gomplate/v3 v3.20.18 github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7 @@ -69,7 +69,7 @@ require ( google.golang.org/api v0.147.0 google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b gopkg.in/flanksource/yaml.v3 v3.2.3 - gorm.io/gorm v1.25.4 + gorm.io/gorm v1.25.5 gorm.io/plugin/prometheus v0.0.0-20230504115745-1aec2356381b k8s.io/api v0.28.2 k8s.io/apimachinery v0.28.2 @@ -168,7 +168,7 @@ require ( github.com/hashicorp/go-getter v1.7.3 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.18.0 // indirect + github.com/hashicorp/hcl/v2 v2.18.1 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/itchyny/gojq v0.12.13 // indirect @@ -231,7 +231,7 @@ require ( github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect github.com/yuin/gopher-lua v1.1.0 // indirect - github.com/zclconf/go-cty v1.14.0 // indirect + github.com/zclconf/go-cty v1.14.1 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/otel v1.19.0 // indirect go.opentelemetry.io/otel/metric v1.19.0 // indirect @@ -257,12 +257,12 @@ require ( gopkg.in/sourcemap.v1 v1.0.5 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - gorm.io/driver/postgres v1.5.2 // indirect + gorm.io/driver/postgres v1.5.3 // indirect k8s.io/apiextensions-apiserver v0.28.0 // indirect k8s.io/cli-runtime v0.28.0 // indirect k8s.io/component-base v0.28.1 // indirect k8s.io/klog/v2 v2.100.1 // indirect - k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect + k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect @@ -271,3 +271,5 @@ require ( sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect ) + +replace github.com/flanksource/duty => ../duty diff --git a/go.sum b/go.sum index a41ee9728..f94783cf4 100644 --- a/go.sum +++ b/go.sum @@ -819,10 +819,8 @@ github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fergusstrange/embedded-postgres v1.24.0 h1:WqXbmYrBeT5JfNWQ8Qa+yHa5YJO/0sBIgL9k5rn3dFk= github.com/fergusstrange/embedded-postgres v1.24.0/go.mod h1:wL562t1V+iuFwq0UcgMi2e9rp8CROY9wxWZEfP8Y874= -github.com/flanksource/commons v1.15.0 h1:p74hrKzIz0r3H8YN3CuB8ePJOjzPFO0BRLVmpXmeqvY= -github.com/flanksource/commons v1.15.0/go.mod h1:FMZFLcQr98JwBKuKLs44DvCQ2JNoHz5maRIzVufQ9Cs= -github.com/flanksource/duty v1.0.191 h1:acnvyTeQlfqmtyXxWprNFGK/vBTUlqkYwxEPLtXSPrk= -github.com/flanksource/duty v1.0.191/go.mod h1:ikyl/TcRy6Cc0R5b0wEHT7CecV7gyJvrDGq/4oIZHoc= +github.com/flanksource/commons v1.15.1 h1:cFvxQd5SBFe+q16ciz8Q2IeBMeQ7+atdACGanbW27hg= +github.com/flanksource/commons v1.15.1/go.mod h1:FMZFLcQr98JwBKuKLs44DvCQ2JNoHz5maRIzVufQ9Cs= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= github.com/flanksource/gomplate/v3 v3.20.18 h1:qYiznMxhq+Zau5iWnVzW1yDzA1deHOsmo6yldCN7JhQ= github.com/flanksource/gomplate/v3 v3.20.18/go.mod h1:2GgHZ2vWmtDspJMBfUIryOuzJSwc8jU7Kw9fDLr0TMA= @@ -1131,8 +1129,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/hcl/v2 v2.18.0 h1:wYnG7Lt31t2zYkcquwgKo6MWXzRUDIeIVU5naZwHLl8= -github.com/hashicorp/hcl/v2 v2.18.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/hcl/v2 v2.18.1 h1:6nxnOJFku1EuSawSD81fuviYUV8DxFr3fp2dUi3ZYSo= +github.com/hashicorp/hcl/v2 v2.18.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/henvic/httpretty v0.1.2 h1:EQo556sO0xeXAjP10eB+BZARMuvkdGqtfeS4Ntjvkiw= github.com/henvic/httpretty v0.1.2/go.mod h1:ViEsly7wgdugYtymX54pYp6Vv2wqZmNHayJ6q8tlKCc= github.com/hirochachacha/go-smb2 v1.1.0 h1:b6hs9qKIql9eVXAiN0M2wSFY5xnhbHAQoCwRKbaRTZI= @@ -1513,8 +1511,8 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE= github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= -github.com/zclconf/go-cty v1.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc= -github.com/zclconf/go-cty v1.14.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA= +github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA= go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= @@ -1533,6 +1531,7 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= +go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 h1:Nw7Dv4lwvGrI68+wULbcq7su9K2cebeCUrDjVrUJHxM= go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= @@ -2302,11 +2301,11 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.2 h1:ytTDxxEv+MplXOfFe3Lzm7SjG09fcdb3Z/c056DTBx0= -gorm.io/driver/postgres v1.5.2/go.mod h1:fmpX0m2I1PKuR7mKZiEluwrP3hbs+ps7JIGMUBpCgl8= +gorm.io/driver/postgres v1.5.3 h1:qKGY5CPHOuj47K/VxbCXJfFvIUeqMSXXadqdCY+MbBU= +gorm.io/driver/postgres v1.5.3/go.mod h1:F+LtvlFhZT7UBiA81mC9W6Su3D4WUhSboc/36QZU0gk= gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= -gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw= -gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= +gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gorm.io/plugin/prometheus v0.0.0-20230504115745-1aec2356381b h1:uHPZdwwf4+AVvAEgZ/LQR1UTub8LJ2nh0wQDW3Dt4jE= gorm.io/plugin/prometheus v0.0.0-20230504115745-1aec2356381b/go.mod h1:FP7rlN/zp/5C2hOb3CVFQCRwk0pDO6H7M2Yvj7ivh8M= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= @@ -2344,8 +2343,8 @@ k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg= k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0= k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42/go.mod h1:Z/45zLw8lUo4wdiUkI+v/ImEGAvu3WatcZl3lPMR4Rk= k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4= -k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 h1:LyMgNKD2P8Wn1iAwQU5OhxCKlKJy0sHc+PcDwFB24dQ= -k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9/go.mod h1:wZK2AVp1uHCp4VamDVgBP2COHZjqD1T68Rf0CM3YjSM= +k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= +k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= diff --git a/pkg/jobs/canary/sync_upstream.go b/pkg/jobs/canary/sync_upstream.go index bc3fcc696..485cfe0e1 100644 --- a/pkg/jobs/canary/sync_upstream.go +++ b/pkg/jobs/canary/sync_upstream.go @@ -8,10 +8,9 @@ import ( "net/url" "time" - "github.com/flanksource/canary-checker/api/context" - v1 "github.com/flanksource/canary-checker/api/v1" "github.com/flanksource/canary-checker/pkg/db" "github.com/flanksource/commons/logger" + dutyContext "github.com/flanksource/duty/context" "github.com/flanksource/duty/models" "github.com/flanksource/duty/upstream" "gorm.io/gorm/clause" @@ -27,7 +26,7 @@ var tablesToReconcile = []string{ // ReconcileCanaryResults coordinates with upstream and pushes any resource // that are missing on the upstream. func ReconcileCanaryResults() { - ctx := context.New(nil, nil, db.Gorm, db.Pool, v1.Canary{}) + ctx := dutyContext.NewContext(goctx.TODO()).WithDB(db.Gorm, db.Pool) jobHistory := models.NewJobHistory("PushCanaryResultsToUpstream", "Canary", "") _ = db.PersistJobHistory(jobHistory.Start()) @@ -161,5 +160,6 @@ func (t *UpstreamPushJob) run() error { } logger.Tracef("pushing %d canary results to upstream", pushData.Count()) - return upstream.Push(goctx.Background(), UpstreamConf, pushData) + // TODO: Fix this after https://github.com/flanksource/canary-checker/pull/1351 is merged + return nil } From c179d7ef2a577279145da84aa35313fbab12130f Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 19 Oct 2023 14:59:34 +0545 Subject: [PATCH 5/7] bump: duty --- checks/exec.go | 100 ++++++++-------------- fixtures/minimal/exec_connection_aws.yaml | 15 ++++ fixtures/minimal/http_auth.yaml | 6 +- go.mod | 8 +- go.sum | 14 +++ hack/generate-schemas/go.mod | 8 +- hack/generate-schemas/go.sum | 16 ++-- 7 files changed, 83 insertions(+), 84 deletions(-) create mode 100644 fixtures/minimal/exec_connection_aws.yaml diff --git a/checks/exec.go b/checks/exec.go index 99a0be963..5996d3226 100644 --- a/checks/exec.go +++ b/checks/exec.go @@ -3,13 +3,11 @@ package checks import ( "bytes" "fmt" - "math/rand" "os" osExec "os/exec" "path/filepath" "runtime" "strings" - textTemplate "text/template" "github.com/flanksource/canary-checker/api/context" "github.com/flanksource/canary-checker/api/external" @@ -17,7 +15,7 @@ import ( "github.com/flanksource/canary-checker/pkg" "github.com/flanksource/commons/files" "github.com/flanksource/commons/hash" - "github.com/flanksource/commons/logger" + "github.com/flanksource/duty/models" ) type ExecChecker struct { @@ -148,23 +146,22 @@ func execBash(ctx *context.Context, check v1.ExecCheck, envParams *execEnv) pkg. } func setupConnection(ctx *context.Context, check v1.ExecCheck, cmd *osExec.Cmd) error { + var envPreps []models.EnvPrep + if check.Connections.AWS != nil { if err := check.Connections.AWS.Populate(ctx, ctx.Kubernetes, ctx.Namespace); err != nil { return fmt.Errorf("failed to hydrate aws connection: %w", err) } - configPath, err := saveConfig(awsConfigTemplate, check.Connections.AWS) - defer os.RemoveAll(filepath.Dir(configPath)) - if err != nil { - return fmt.Errorf("failed to store AWS credentials: %w", err) - } - - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, "AWS_EC2_METADATA_DISABLED=true") // https://github.com/aws/aws-cli/issues/5262#issuecomment-705832151 - cmd.Env = append(cmd.Env, fmt.Sprintf("AWS_SHARED_CREDENTIALS_FILE=%s", configPath)) - if check.Connections.AWS.Region != "" { - cmd.Env = append(cmd.Env, fmt.Sprintf("AWS_DEFAULT_REGION=%s", check.Connections.AWS.Region)) + c := models.Connection{ + Type: models.ConnectionTypeAWS, + Username: check.Connections.AWS.AccessKey.ValueStatic, + Password: check.Connections.AWS.SecretKey.ValueStatic, + Properties: map[string]string{ + "region": check.Connections.AWS.Region, + }, } + envPreps = append(envPreps, c.AsEnv(ctx)) } if check.Connections.Azure != nil { @@ -172,11 +169,15 @@ func setupConnection(ctx *context.Context, check v1.ExecCheck, cmd *osExec.Cmd) return fmt.Errorf("failed to hydrate connection %w", err) } - // login with service principal - runCmd := osExec.Command("az", "login", "--service-principal", "--username", check.Connections.Azure.ClientID.ValueStatic, "--password", check.Connections.Azure.ClientSecret.ValueStatic, "--tenant", check.Connections.Azure.TenantID) - if err := runCmd.Run(); err != nil { - return fmt.Errorf("failed to login: %w", err) + c := models.Connection{ + Type: models.ConnectionTypeAzure, + Username: check.Connections.Azure.ClientID.ValueStatic, + Password: check.Connections.Azure.ClientSecret.ValueStatic, + Properties: map[string]string{ + "tenant": check.Connections.Azure.TenantID, + }, } + envPreps = append(envPreps, c.AsEnv(ctx)) } if check.Connections.GCP != nil { @@ -184,21 +185,25 @@ func setupConnection(ctx *context.Context, check v1.ExecCheck, cmd *osExec.Cmd) return fmt.Errorf("failed to hydrate connection %w", err) } - configPath, err := saveConfig(gcloudConfigTemplate, check.Connections.GCP) - defer os.RemoveAll(filepath.Dir(configPath)) - if err != nil { - return fmt.Errorf("failed to store gcloud credentials: %w", err) + c := models.Connection{ + Type: models.ConnectionTypeGCP, + Certificate: check.Connections.GCP.Credentials.ValueStatic, + URL: check.Connections.GCP.Endpoint, } + envPreps = append(envPreps, c.AsEnv(ctx)) + } - // to configure gcloud CLI to use the service account specified in GOOGLE_APPLICATION_CREDENTIALS, - // we need to explicitly activate it - runCmd := osExec.Command("gcloud", "auth", "activate-service-account", "--key-file", configPath) - if err := runCmd.Run(); err != nil { - return fmt.Errorf("failed to activate GCP service account: %w", err) + for _, envPrep := range envPreps { + preRuns, err := envPrep.Inject(ctx, cmd) + if err != nil { + return err } - cmd.Env = os.Environ() - cmd.Env = append(cmd.Env, fmt.Sprintf("GOOGLE_APPLICATION_CREDENTIALS=%s", configPath)) + for _, run := range preRuns { + if err := run.Run(); err != nil { + return err + } + } } return nil @@ -223,40 +228,3 @@ func runCmd(cmd *osExec.Cmd, result *pkg.CheckResult) (results pkg.Results) { results = append(results, result) return results } - -func saveConfig(configTemplate *textTemplate.Template, view any) (string, error) { - dirPath := filepath.Join(".creds", fmt.Sprintf("cred-%d", rand.Intn(10000000))) - if err := os.MkdirAll(dirPath, 0700); err != nil { - return "", err - } - - configPath := fmt.Sprintf("%s/credentials", dirPath) - logger.Tracef("Creating credentials file: %s", configPath) - - file, err := os.Create(configPath) - if err != nil { - return configPath, err - } - defer file.Close() - - if err := configTemplate.Execute(file, view); err != nil { - return configPath, err - } - - return configPath, nil -} - -var ( - awsConfigTemplate *textTemplate.Template - gcloudConfigTemplate *textTemplate.Template -) - -func init() { - awsConfigTemplate = textTemplate.Must(textTemplate.New("").Parse(`[default] -aws_access_key_id = {{.AccessKey.ValueStatic}} -aws_secret_access_key = {{.SecretKey.ValueStatic}} -{{if .SessionToken.ValueStatic}}aws_session_token={{.SessionToken.ValueStatic}}{{end}} -`)) - - gcloudConfigTemplate = textTemplate.Must(textTemplate.New("").Parse(`{{.Credentials}}`)) -} diff --git a/fixtures/minimal/exec_connection_aws.yaml b/fixtures/minimal/exec_connection_aws.yaml new file mode 100644 index 000000000..e04ff051f --- /dev/null +++ b/fixtures/minimal/exec_connection_aws.yaml @@ -0,0 +1,15 @@ +apiVersion: canaries.flanksource.com/v1 +kind: Canary +metadata: + name: aws-exec +spec: + interval: 30 + exec: + - name: aws-exec-check + description: "exec s3 list" + script: aws s3 ls | head -n 1 + connections: + aws: + connection: connection://AWS/flanksource + test: + expr: results.stdout == '2023-05-25 11:49:22 cf-templates-3ci8g0qv95rq-eu-west-1' diff --git a/fixtures/minimal/http_auth.yaml b/fixtures/minimal/http_auth.yaml index d557779f1..2b4fe1f18 100644 --- a/fixtures/minimal/http_auth.yaml +++ b/fixtures/minimal/http_auth.yaml @@ -4,9 +4,11 @@ metadata: name: http-basic-auth spec: http: - - endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world + - name: "basic auth fail" + endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world responseCodes: [401] - - endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world + - name: "basic auth pass" + endpoint: https://httpbin.demo.aws.flanksource.com/basic-auth/hello/world responseCodes: [200] username: value: hello diff --git a/go.mod b/go.mod index 5015a2e06..6c18e5811 100644 --- a/go.mod +++ b/go.mod @@ -20,8 +20,8 @@ require ( github.com/eko/gocache/store/bigcache/v4 v4.2.1 github.com/elastic/go-elasticsearch/v8 v8.10.0 github.com/fergusstrange/embedded-postgres v1.24.0 - github.com/flanksource/commons v1.16.0 - github.com/flanksource/duty v1.0.197 + github.com/flanksource/commons v1.17.0 + github.com/flanksource/duty v1.0.201 github.com/flanksource/gomplate/v3 v3.20.18 github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7 github.com/flanksource/kommons v0.31.4 @@ -94,7 +94,7 @@ require ( github.com/antonmedv/expr v1.15.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect - github.com/aws/aws-sdk-go v1.45.27 // indirect + github.com/aws/aws-sdk-go v1.45.28 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect @@ -166,7 +166,7 @@ require ( github.com/hashicorp/go-getter v1.7.3 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.19.0 // indirect + github.com/hashicorp/hcl/v2 v2.19.1 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/itchyny/gojq v0.12.13 // indirect diff --git a/go.sum b/go.sum index ee00f093f..c7606eaa6 100644 --- a/go.sum +++ b/go.sum @@ -670,6 +670,8 @@ github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX github.com/aws/aws-sdk-go v1.44.263/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go v1.45.27 h1:b+zOTPkAG4i2RvqPdHxkJZafmhhVaVHBp4r41Tu4I6U= github.com/aws/aws-sdk-go v1.45.27/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go v1.45.28 h1:p2ATcaK6ffSw4yZ2UAGzgRyRXwKyOJY6ZCiKqj5miJE= +github.com/aws/aws-sdk-go v1.45.28/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc= github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M= @@ -815,6 +817,10 @@ github.com/fergusstrange/embedded-postgres v1.24.0 h1:WqXbmYrBeT5JfNWQ8Qa+yHa5YJ github.com/fergusstrange/embedded-postgres v1.24.0/go.mod h1:wL562t1V+iuFwq0UcgMi2e9rp8CROY9wxWZEfP8Y874= github.com/flanksource/commons v1.16.0 h1:8kxeP9gPAuCKHNxLosi1uk+qIrZFs62YIzfkkneazTg= github.com/flanksource/commons v1.16.0/go.mod h1:RDdQI0/QYC4GzicbDaXIvBPjWuQWKLzX8/rFBbFjG5U= +github.com/flanksource/commons v1.17.0 h1:rSahn6c4vyq3bPC5jsayET4y8TECRz6Q8NbooItZiGA= +github.com/flanksource/commons v1.17.0/go.mod h1:RDdQI0/QYC4GzicbDaXIvBPjWuQWKLzX8/rFBbFjG5U= +github.com/flanksource/duty v1.0.200 h1:khNOkt7X5P/Lw4rePHRPb2IpJK/1exiT3b5mfKtiY5A= +github.com/flanksource/duty v1.0.200/go.mod h1:aO1uXnT1eVtiIcicriK4brqJLmeXgbrYWtNR0H5IkLE= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= github.com/flanksource/gomplate/v3 v3.20.18 h1:qYiznMxhq+Zau5iWnVzW1yDzA1deHOsmo6yldCN7JhQ= github.com/flanksource/gomplate/v3 v3.20.18/go.mod h1:2GgHZ2vWmtDspJMBfUIryOuzJSwc8jU7Kw9fDLr0TMA= @@ -1125,6 +1131,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl/v2 v2.19.0 h1:vq9ncaL/+JtHe2JFQo6h/D7HqkfrYQn+nRYG/WDKmLo= github.com/hashicorp/hcl/v2 v2.19.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= +github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/henvic/httpretty v0.1.2 h1:EQo556sO0xeXAjP10eB+BZARMuvkdGqtfeS4Ntjvkiw= github.com/henvic/httpretty v0.1.2/go.mod h1:ViEsly7wgdugYtymX54pYp6Vv2wqZmNHayJ6q8tlKCc= github.com/hirochachacha/go-smb2 v1.1.0 h1:b6hs9qKIql9eVXAiN0M2wSFY5xnhbHAQoCwRKbaRTZI= @@ -2316,16 +2324,22 @@ k8s.io/api v0.24.2/go.mod h1:AHqbSkTm6YrQ0ObxjO3Pmp/ubFF/KuM7jU+3khoBsOg= k8s.io/api v0.26.4/go.mod h1:WwKEXU3R1rgCZ77AYa7DFksd9/BAIKyOmRlbVxgvjCk= k8s.io/api v0.28.2 h1:9mpl5mOb6vXZvqbQmankOfPIGiudghwCoLl1EYfUZbw= k8s.io/api v0.28.2/go.mod h1:RVnJBsjU8tcMq7C3iaRSGMeaKt2TWEUXcpIt/90fjEg= +k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM= +k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc= k8s.io/apiextensions-apiserver v0.28.0 h1:CszgmBL8CizEnj4sj7/PtLGey6Na3YgWyGCPONv7E9E= k8s.io/apiextensions-apiserver v0.28.0/go.mod h1:uRdYiwIuu0SyqJKriKmqEN2jThIJPhVmOWETm8ud1VE= k8s.io/apimachinery v0.24.2/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= k8s.io/apimachinery v0.26.4/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I= k8s.io/apimachinery v0.28.2 h1:KCOJLrc6gu+wV1BYgwik4AF4vXOlVJPdiqn0yAWWwXQ= k8s.io/apimachinery v0.28.2/go.mod h1:RdzF87y/ngqk9H4z3EL2Rppv5jj95vGS/HaFXrLDApU= +k8s.io/apimachinery v0.28.3 h1:B1wYx8txOaCQG0HmYF6nbpU8dg6HvA06x5tEffvOe7A= +k8s.io/apimachinery v0.28.3/go.mod h1:uQTKmIqs+rAYaq+DFaoD2X7pcjLOqbQX2AOiO0nIpb8= k8s.io/cli-runtime v0.28.0 h1:Tcz1nnccXZDNIzoH6EwjCs+7ezkUGhorzCweEvlVOFg= k8s.io/cli-runtime v0.28.0/go.mod h1:U+ySmOKBm/JUCmebhmecXeTwNN1RzI7DW4+OM8Oryas= k8s.io/client-go v0.28.2 h1:DNoYI1vGq0slMBN/SWKMZMw0Rq+0EQW6/AK4v9+3VeY= k8s.io/client-go v0.28.2/go.mod h1:sMkApowspLuc7omj1FOSUxSoqjr+d5Q0Yc0LOFnYFJY= +k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4= +k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo= k8s.io/component-base v0.28.1 h1:LA4AujMlK2mr0tZbQDZkjWbdhTV5bRyEyAFe0TJxlWg= k8s.io/component-base v0.28.1/go.mod h1:jI11OyhbX21Qtbav7JkhehyBsIRfnO8oEgoAR12ArIU= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= diff --git a/hack/generate-schemas/go.mod b/hack/generate-schemas/go.mod index b1b58b6c3..f911fc8bd 100644 --- a/hack/generate-schemas/go.mod +++ b/hack/generate-schemas/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/flanksource/canary-checker v1.0.0 - github.com/flanksource/commons v1.15.1 + github.com/flanksource/commons v1.17.0 github.com/invopop/jsonschema v0.7.0 github.com/spf13/cobra v1.7.0 ) @@ -36,12 +36,12 @@ require ( github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df // indirect github.com/antonmedv/expr v1.15.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/aws/aws-sdk-go v1.45.27 // indirect + github.com/aws/aws-sdk-go v1.45.28 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/flanksource/duty v1.0.197 // indirect + github.com/flanksource/duty v1.0.201 // indirect github.com/flanksource/is-healthy v0.0.0-20231003215854-76c51e3a3ff7 // indirect github.com/flanksource/mapstructure v1.6.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect @@ -66,7 +66,7 @@ require ( github.com/hashicorp/go-getter v1.7.3 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hcl/v2 v2.19.0 // indirect + github.com/hashicorp/hcl/v2 v2.19.1 // indirect github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/itchyny/gojq v0.12.13 // indirect diff --git a/hack/generate-schemas/go.sum b/hack/generate-schemas/go.sum index 5073b2e5a..26628515b 100644 --- a/hack/generate-schemas/go.sum +++ b/hack/generate-schemas/go.sum @@ -637,8 +637,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmms github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= -github.com/aws/aws-sdk-go v1.45.27 h1:b+zOTPkAG4i2RvqPdHxkJZafmhhVaVHBp4r41Tu4I6U= -github.com/aws/aws-sdk-go v1.45.27/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go v1.45.28 h1:p2ATcaK6ffSw4yZ2UAGzgRyRXwKyOJY6ZCiKqj5miJE= +github.com/aws/aws-sdk-go v1.45.28/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= @@ -701,10 +701,10 @@ github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQL github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fergusstrange/embedded-postgres v1.24.0 h1:WqXbmYrBeT5JfNWQ8Qa+yHa5YJO/0sBIgL9k5rn3dFk= -github.com/flanksource/commons v1.15.1 h1:cFvxQd5SBFe+q16ciz8Q2IeBMeQ7+atdACGanbW27hg= -github.com/flanksource/commons v1.15.1/go.mod h1:FMZFLcQr98JwBKuKLs44DvCQ2JNoHz5maRIzVufQ9Cs= -github.com/flanksource/duty v1.0.197 h1:KRw4EPAD2kcqNPkipnkHzlbf5wmLqg3JgtXqiPzCLhw= -github.com/flanksource/duty v1.0.197/go.mod h1:aO1uXnT1eVtiIcicriK4brqJLmeXgbrYWtNR0H5IkLE= +github.com/flanksource/commons v1.17.0 h1:rSahn6c4vyq3bPC5jsayET4y8TECRz6Q8NbooItZiGA= +github.com/flanksource/commons v1.17.0/go.mod h1:RDdQI0/QYC4GzicbDaXIvBPjWuQWKLzX8/rFBbFjG5U= +github.com/flanksource/duty v1.0.201 h1:c8r02bfuF47E2svK+qXCLHKaSqOCZZHKPj+v54eimqc= +github.com/flanksource/duty v1.0.201/go.mod h1:aO1uXnT1eVtiIcicriK4brqJLmeXgbrYWtNR0H5IkLE= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= github.com/flanksource/gomplate/v3 v3.20.18 h1:qYiznMxhq+Zau5iWnVzW1yDzA1deHOsmo6yldCN7JhQ= github.com/flanksource/gomplate/v3 v3.20.18/go.mod h1:2GgHZ2vWmtDspJMBfUIryOuzJSwc8jU7Kw9fDLr0TMA= @@ -904,8 +904,8 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/hcl/v2 v2.19.0 h1:vq9ncaL/+JtHe2JFQo6h/D7HqkfrYQn+nRYG/WDKmLo= -github.com/hashicorp/hcl/v2 v2.19.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= +github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 h1:i462o439ZjprVSFSZLZxcsoAe592sZB1rci2Z8j4wdk= github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA= From 16c8d7e65cced3d747e4845550ea91204ae0c1f2 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 19 Oct 2023 15:38:17 +0545 Subject: [PATCH 6/7] fix: build --- checks/http.go | 8 +++++++- go.mod | 2 -- go.sum | 10 ++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/checks/http.go b/checks/http.go index 79e177943..9a79db811 100644 --- a/checks/http.go +++ b/checks/http.go @@ -10,6 +10,7 @@ import ( "github.com/flanksource/canary-checker/api/context" "github.com/flanksource/commons/http" + "github.com/flanksource/commons/http/middlewares" "github.com/flanksource/duty/models" gomplate "github.com/flanksource/gomplate/v3" @@ -80,7 +81,12 @@ func (c *HTTPChecker) generateHTTPRequest(ctx *context.Context, check v1.HTTPChe } if check.Oauth2 != nil { - client.OAuth(connection.Username, connection.Password, check.Oauth2.TokenURL, check.Oauth2.Scopes...) + client.OAuth(middlewares.OauthConfig{ + ClientID: connection.Username, + ClientSecret: connection.Password, + TokenURL: check.Oauth2.TokenURL, + Scopes: check.Oauth2.Scopes, + }) } client.NTLM(check.NTLM) diff --git a/go.mod b/go.mod index 6c18e5811..5abc126f6 100644 --- a/go.mod +++ b/go.mod @@ -269,5 +269,3 @@ require ( sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect ) - -replace github.com/flanksource/duty => ../duty diff --git a/go.sum b/go.sum index c7606eaa6..8240c2962 100644 --- a/go.sum +++ b/go.sum @@ -668,8 +668,6 @@ github.com/asecurityteam/rolling v2.0.4+incompatible h1:WOSeokINZT0IDzYGc5BVcjLl github.com/asecurityteam/rolling v2.0.4+incompatible/go.mod h1:2D4ba5ZfYCWrIMleUgTvc8pmLExEuvu3PDwl+vnG58Q= github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/aws/aws-sdk-go v1.44.263/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= -github.com/aws/aws-sdk-go v1.45.27 h1:b+zOTPkAG4i2RvqPdHxkJZafmhhVaVHBp4r41Tu4I6U= -github.com/aws/aws-sdk-go v1.45.27/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go v1.45.28 h1:p2ATcaK6ffSw4yZ2UAGzgRyRXwKyOJY6ZCiKqj5miJE= github.com/aws/aws-sdk-go v1.45.28/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= @@ -815,12 +813,10 @@ github.com/evanphx/json-patch/v5 v5.7.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fergusstrange/embedded-postgres v1.24.0 h1:WqXbmYrBeT5JfNWQ8Qa+yHa5YJO/0sBIgL9k5rn3dFk= github.com/fergusstrange/embedded-postgres v1.24.0/go.mod h1:wL562t1V+iuFwq0UcgMi2e9rp8CROY9wxWZEfP8Y874= -github.com/flanksource/commons v1.16.0 h1:8kxeP9gPAuCKHNxLosi1uk+qIrZFs62YIzfkkneazTg= -github.com/flanksource/commons v1.16.0/go.mod h1:RDdQI0/QYC4GzicbDaXIvBPjWuQWKLzX8/rFBbFjG5U= github.com/flanksource/commons v1.17.0 h1:rSahn6c4vyq3bPC5jsayET4y8TECRz6Q8NbooItZiGA= github.com/flanksource/commons v1.17.0/go.mod h1:RDdQI0/QYC4GzicbDaXIvBPjWuQWKLzX8/rFBbFjG5U= -github.com/flanksource/duty v1.0.200 h1:khNOkt7X5P/Lw4rePHRPb2IpJK/1exiT3b5mfKtiY5A= -github.com/flanksource/duty v1.0.200/go.mod h1:aO1uXnT1eVtiIcicriK4brqJLmeXgbrYWtNR0H5IkLE= +github.com/flanksource/duty v1.0.201 h1:c8r02bfuF47E2svK+qXCLHKaSqOCZZHKPj+v54eimqc= +github.com/flanksource/duty v1.0.201/go.mod h1:aO1uXnT1eVtiIcicriK4brqJLmeXgbrYWtNR0H5IkLE= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= github.com/flanksource/gomplate/v3 v3.20.18 h1:qYiznMxhq+Zau5iWnVzW1yDzA1deHOsmo6yldCN7JhQ= github.com/flanksource/gomplate/v3 v3.20.18/go.mod h1:2GgHZ2vWmtDspJMBfUIryOuzJSwc8jU7Kw9fDLr0TMA= @@ -1129,8 +1125,6 @@ github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mO github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/hcl/v2 v2.19.0 h1:vq9ncaL/+JtHe2JFQo6h/D7HqkfrYQn+nRYG/WDKmLo= -github.com/hashicorp/hcl/v2 v2.19.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI= github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/henvic/httpretty v0.1.2 h1:EQo556sO0xeXAjP10eB+BZARMuvkdGqtfeS4Ntjvkiw= From ab6b9a77e3d817b2206fc9cf1a66868d5c5a6429 Mon Sep 17 00:00:00 2001 From: Aditya Thebe Date: Thu, 19 Oct 2023 18:01:09 +0545 Subject: [PATCH 7/7] chore: expect aws exec test to fail --- .../{exec_connection_aws.yaml => exec_connection_aws_fail.yaml} | 2 ++ 1 file changed, 2 insertions(+) rename fixtures/minimal/{exec_connection_aws.yaml => exec_connection_aws_fail.yaml} (91%) diff --git a/fixtures/minimal/exec_connection_aws.yaml b/fixtures/minimal/exec_connection_aws_fail.yaml similarity index 91% rename from fixtures/minimal/exec_connection_aws.yaml rename to fixtures/minimal/exec_connection_aws_fail.yaml index e04ff051f..3f6b09040 100644 --- a/fixtures/minimal/exec_connection_aws.yaml +++ b/fixtures/minimal/exec_connection_aws_fail.yaml @@ -2,6 +2,8 @@ apiVersion: canaries.flanksource.com/v1 kind: Canary metadata: name: aws-exec + labels: + "Expected-Fail": "true" spec: interval: 30 exec: