From 20dd00d1e165eb549fea4b0b603e3e44ef73c5d4 Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Wed, 26 Jun 2024 16:50:16 +0200 Subject: [PATCH] Extract proxy url --- policy/data/proxy/client.go | 12 +++++------- policy/policy_handler/proxy.go | 8 ++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/policy/data/proxy/client.go b/policy/data/proxy/client.go index a6f092c..c72d713 100644 --- a/policy/data/proxy/client.go +++ b/policy/data/proxy/client.go @@ -18,14 +18,13 @@ type ProxyClient struct { correlationId string gqlUrl string entitlementsUrl string - proxyUrl string } -func NewProxyClientFromSkillRequest(ctx context.Context, proxyUrl string, req skill.RequestContext) ProxyClient { - return NewProxyClient(ctx, proxyUrl, req.Event.Urls.Graphql, req.Event.Urls.Entitlements, req.Event.Token, req.Event.ExecutionId) +func NewProxyClientFromSkillRequest(ctx context.Context, req skill.RequestContext) ProxyClient { + return NewProxyClient(ctx, req.Event.Urls.Graphql, req.Event.Urls.Entitlements, req.Event.Token, req.Event.ExecutionId) } -func NewProxyClient(ctx context.Context, proxyUrl, graphqlUrl, entitlementsUrl, token, correlationId string) ProxyClient { +func NewProxyClient(ctx context.Context, graphqlUrl, entitlementsUrl, token, correlationId string) ProxyClient { httpClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token, TokenType: "Bearer"}, )) @@ -33,11 +32,10 @@ func NewProxyClient(ctx context.Context, proxyUrl, graphqlUrl, entitlementsUrl, return ProxyClient{ httpClient: *httpClient, correlationId: correlationId, - proxyUrl: proxyUrl, } } -func (c *ProxyClient) Evaluate(ctx context.Context, organization, teamId string, sbom *types.SBOM, args map[string]interface{}) (goals.EvaluationResult, error) { +func (c *ProxyClient) Evaluate(ctx context.Context, organization, teamId, url string, sbom *types.SBOM, args map[string]interface{}) (goals.EvaluationResult, error) { preq := EvaluateRequest{ EvaluateOptions: EvaluateOptions{ Organization: organization, @@ -56,7 +54,7 @@ func (c *ProxyClient) Evaluate(ctx context.Context, organization, teamId string, return goals.EvaluationResult{}, err } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.proxyUrl, bytes.NewReader(data)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(data)) if err != nil { return goals.EvaluationResult{}, err } diff --git a/policy/policy_handler/proxy.go b/policy/policy_handler/proxy.go index fa6766b..2ab6ddd 100644 --- a/policy/policy_handler/proxy.go +++ b/policy/policy_handler/proxy.go @@ -7,15 +7,15 @@ import ( "github.com/atomist-skills/go-skill/policy/data/proxy" ) -func WithProxyClient(url string) Opt { +func WithProxyClient() Opt { return func(h *EventHandler) { - provider := getProxyClientProvider(url) + provider := getProxyClientProvider() h.proxyClientProvider = &provider } } -func getProxyClientProvider(url string) proxyClientProvider { +func getProxyClientProvider() proxyClientProvider { return func(ctx context.Context, req skill.RequestContext) proxy.ProxyClient { - return proxy.NewProxyClientFromSkillRequest(ctx, url, req) + return proxy.NewProxyClientFromSkillRequest(ctx, req) } }