Skip to content

Commit

Permalink
Extract proxy url
Browse files Browse the repository at this point in the history
  • Loading branch information
cdupuis committed Jun 26, 2024
1 parent cf43447 commit 20dd00d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions policy/data/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@ 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"},
))

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,
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions policy/policy_handler/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 20dd00d

Please sign in to comment.