diff --git a/inttests/upgrade_test.go b/inttests/upgrade_test.go index 585713d..b9c0097 100644 --- a/inttests/upgrade_test.go +++ b/inttests/upgrade_test.go @@ -61,3 +61,24 @@ 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) +} diff --git a/upgrade.go b/upgrade.go index 9c454d9..501aabd 100644 --- a/upgrade.go +++ b/upgrade.go @@ -298,3 +298,72 @@ func (gc *GatewayClient) GetFirmwareRepositoryDetailsUsingName(name string) (*ty } return frDetails, err } + +// DeleteFirmwareRepository deletes the particular firmware repository +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 +} + +// TestConnection tests the connection to the source location. +func (gc *GatewayClient) TestConnection(uploadComplianceParam *types.UploadComplianceParam) error { + 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") + } + + err3 := storeCookie(httpResp.Header, gc.host) + if err3 != nil { + return fmt.Errorf("Error While Storing cookie: %s", err3) + } + + return nil +}