Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: http client and deepcode client [IDE-195] #22

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

teodora-sandu
Copy link
Contributor

@teodora-sandu teodora-sandu commented Apr 5, 2024

Refactors the HTTP client, so that it's a general client that can be used when making calls to the Workspace and Orchestration API as part of https://snyksec.atlassian.net/browse/IDE-195.

This means:

  • move DeepCode specific code to the deepcode package from the http package
  • the HTTP client in the http package is just a client with retries and can then be used to pass to the clients generated by oapi-codegen

Tested it with snyk-ls and snyk-intellij-plugin by following https://snyksec.atlassian.net/wiki/spaces/IDE/pages/1966866488/How+to+setup+development+for+Consistent+Ignores

@teodora-sandu teodora-sandu marked this pull request as ready for review April 5, 2024 14:49
@teodora-sandu teodora-sandu requested a review from a team as a code owner April 5, 2024 14:49
@teodora-sandu teodora-sandu force-pushed the refactor/http-client branch 3 times, most recently from 6a6ca0c to 75fe4ab Compare April 5, 2024 15:39
@teodora-sandu teodora-sandu changed the title refactor: http client and code scanner [IDE-195] refactor: http client and deepcode client [IDE-195] Apr 5, 2024
@teodora-sandu teodora-sandu force-pushed the refactor/http-client branch from bc53a53 to 95364d6 Compare April 5, 2024 16:21
}

func NewSnykCodeClient(
logger *zerolog.Logger,
httpClient codeClientHTTP.HTTPClient,
instrumentor observability.Instrumentor,
errorReporter observability.ErrorReporter,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider using the Function Options Pattern, as the constructor parameters are growing quite a bit :).

I also wonder, if we do that, if we should assume sensible defaults for errorReporter, e.g implementing an error reporter that just logs, an instrumentor that does nothing etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, that's very similar to what I did in #23 for the code scanner. This deepcode client is hopefully not going to be here very long so I think I will leave it as is for now and look at doing what you suggested after PR#23 gets merged.

deepcode/client.go Outdated Show resolved Hide resolved
if err != nil {
return "", nil, err
}
var bundleResponse BundleResponse
err = json.Unmarshal(responseBody, &bundleResponse)
return bundleResponse.BundleHash, bundleResponse.MissingFiles, err
}

// This is only exported for tests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be an option, to just use the same package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're doing blackbox testing here. Technically I should not test this function but the code I extracted from snyk-ls was testing it and I wanted to keep it to make sure it continue working. I'll maybe think about writing the other tests in a way that tests this function too


// This is only exported for tests.
func (s *snykCodeClient) Host() (string, error) {
var codeApiRegex = regexp.MustCompile(`^(deeproxy\.)?`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not correct - for local code engine and on Fedramp, it is not always deeproxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@bastiandoetsch bastiandoetsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teodora-sandu teodora-sandu force-pushed the refactor/http-client branch from 95364d6 to a3a873b Compare April 8, 2024 13:51
@teodora-sandu teodora-sandu force-pushed the refactor/http-client branch from a3a873b to dc43572 Compare April 8, 2024 14:06
@teodora-sandu teodora-sandu merged commit cacecab into main Apr 8, 2024
10 checks passed
@teodora-sandu teodora-sandu deleted the refactor/http-client branch April 8, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants