Skip to content

Commit

Permalink
Code cleanup (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
4ernovm authored Dec 6, 2023
1 parent 155b214 commit a65255f
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 25 deletions.
12 changes: 1 addition & 11 deletions internal/client/deb_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ type IDebClient interface {
// Get makes a GET request to one of Debricked's API endpoints
Get(uri string, format string) (*http.Response, error)
SetAccessToken(accessToken *string)
ConfigureClientSettings(retry bool, timeout int)
}

type DebClient struct {
host *string
httpClient IClient
accessToken *string
jwtToken string
retry bool
timeout int
}

func NewDebClient(accessToken *string, httpClient IClient) *DebClient {
Expand All @@ -38,8 +35,6 @@ func NewDebClient(accessToken *string, httpClient IClient) *DebClient {
httpClient: httpClient,
accessToken: initAccessToken(accessToken),
jwtToken: "",
retry: true,
timeout: DefaultTimeout,
}
}

Expand All @@ -52,18 +47,13 @@ func (debClient *DebClient) Post(uri string, contentType string, body *bytes.Buf
}

func (debClient *DebClient) Get(uri string, format string) (*http.Response, error) {
return get(uri, debClient, debClient.retry, format)
return get(uri, debClient, true, format)
}

func (debClient *DebClient) SetAccessToken(accessToken *string) {
debClient.accessToken = initAccessToken(accessToken)
}

func (debClient *DebClient) ConfigureClientSettings(retry bool, timeout int) {
debClient.retry = retry
debClient.timeout = timeout
}

func initAccessToken(accessToken *string) *string {
if accessToken == nil {
accessToken = new(string)
Expand Down
7 changes: 0 additions & 7 deletions internal/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ func post(uri string, debClient *DebClient, contentType string, body *bytes.Buff
}
request.Header.Add("Content-Type", contentType)

if debClient.timeout > 0 {
timeoutDuration := time.Duration(debClient.timeout) * time.Second
ctx, cancel := context.WithTimeout(request.Context(), timeoutDuration)
defer cancel()
request = request.WithContext(ctx)
}

res, err := debClient.httpClient.Do(request)
if err != nil {
return nil, err
Expand Down
2 changes: 0 additions & 2 deletions internal/client/testdata/deb_client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func (mock *DebClientMock) Post(uri string, format string, body *bytes.Buffer, t

func (mock *DebClientMock) SetAccessToken(_ *string) {}

func (mock *DebClientMock) ConfigureClientSettings(retry bool, timeout int) {}

type MockResponse struct {
StatusCode int
ResponseBody io.ReadCloser
Expand Down
3 changes: 0 additions & 3 deletions internal/file/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ func (finder *Finder) GetSupportedFormats() ([]*CompiledFormat, error) {
}

func (finder *Finder) GetSupportedFormatsJson() ([]byte, error) {
finder.debClient.ConfigureClientSettings(false, 5)
defer finder.debClient.ConfigureClientSettings(true, 15)

res, err := finder.debClient.Get(SupportedFormatsUri, "application/json")

if err != nil || res.StatusCode != http.StatusOK {
Expand Down
2 changes: 0 additions & 2 deletions internal/upload/uploader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,3 @@ func (mock *debClientMock) Get(_ string, _ string) (*http.Response, error) {
}

func (mock *debClientMock) SetAccessToken(_ *string) {}

func (mock *debClientMock) ConfigureClientSettings(retry bool, timeout int) {}

0 comments on commit a65255f

Please sign in to comment.