Skip to content

Commit

Permalink
added delete and testing connection functionality for FR
Browse files Browse the repository at this point in the history
  • Loading branch information
AnikaAgiwal2711 committed Jun 14, 2024
1 parent 3e3d60c commit d1dd28b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
22 changes: 22 additions & 0 deletions inttests/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,25 @@ func TestApproveUnsignedFile(t *testing.T) {
err := GC.ApproveUnsignedFile(unsigned)
assert.Nil(t, err)
}

func TestDeleteFirmwareRepository(t *testing.T) {
var id string
if os.Getenv("GOSCALEIO_COMPLIANCE_FILE_ID_FOR_DELETE") != "" {
id = os.Getenv("GOSCALEIO_COMPLIANCE_FILE_ID_FOR_DELETE")
}
err := GC.DeleteFirmwareRepository(id)
assert.Nil(t, err)
}

func TestConnection(t *testing.T) {
var sourceLocation string
if os.Getenv("GOSCALEIO_COMPLIANCE_ENDPOINT") != "" {
sourceLocation = os.Getenv("GOSCALEIO_COMPLIANCE_ENDPOINT")
}
ucParam := &types.UploadComplianceParam{
SourceLocation: sourceLocation,
}
err := GC.TestConnection(ucParam)
assert.Nil(t, err)

Check failure on line 84 in inttests/upgrade_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
}
69 changes: 69 additions & 0 deletions upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,72 @@ func (gc *GatewayClient) GetFirmwareRepositoryDetailsUsingName(name string) (*ty
}
return frDetails, err
}

func (gc *GatewayClient) DeleteFirmwareRepository(id string) error {
req, httpError := http.NewRequest(http.MethodDelete, gc.host+"/Api/V1/FirmwareRepository/"+id, nil)
if httpError != nil {
return httpError
}

req.Header.Set("Authorization", "Bearer "+gc.token)
setCookieError := setCookie(req.Header, gc.host)
if setCookieError != nil {
return fmt.Errorf("Error While Handling Cookie: %s", setCookieError)
}
req.Header.Set("Content-Type", "application/json")

client := gc.http
httpResp, httpRespError := client.Do(req)
if httpRespError != nil {
return httpRespError
}

if httpResp.StatusCode != http.StatusNoContent {
return fmt.Errorf("Error while deleting firmware repository")
}

err3 := storeCookie(httpResp.Header, gc.host)
if err3 != nil {
return fmt.Errorf("Error While Storing cookie: %s", err3)
}

return nil

Check failure on line 331 in upgrade.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
}

func (gc *GatewayClient) TestConnection(uploadComplianceParam *types.UploadComplianceParam) error {

Check failure on line 335 in upgrade.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
jsonData, err := json.Marshal(uploadComplianceParam)
if err != nil {
return err
}

req, httpError := http.NewRequest(http.MethodPost, gc.host+"/Api/V1/FirmwareRepository/connection", bytes.NewBuffer(jsonData))
if httpError != nil {
return httpError
}

req.Header.Set("Authorization", "Bearer "+gc.token)
setCookieError := setCookie(req.Header, gc.host)
if setCookieError != nil {
return fmt.Errorf("Error While Handling Cookie: %s", setCookieError)
}
req.Header.Set("Content-Type", "application/json")

client := gc.http
httpResp, httpRespError := client.Do(req)
if httpRespError != nil {
return httpRespError
}

if httpResp.StatusCode != http.StatusNoContent {
return fmt.Errorf("Error while connecting to the source location. Please chack the credentials.")

Check warning on line 360 in upgrade.go

View workflow job for this annotation

GitHub Actions / golangci-lint

error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
}

err3 := storeCookie(httpResp.Header, gc.host)
if err3 != nil {
return fmt.Errorf("Error While Storing cookie: %s", err3)
}

return nil
}

0 comments on commit d1dd28b

Please sign in to comment.