|
| 1 | +package secure |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "fmt" |
| 7 | + "io/ioutil" |
| 8 | + "net/http" |
| 9 | +) |
| 10 | + |
| 11 | +func (client *sysdigSecureClient) CreateVulnerabilityExceptionList(ctx context.Context, list *VulnerabilityExceptionList) (*VulnerabilityExceptionList, error) { |
| 12 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodPost, client.getVulnerabilityExceptionListURL(), list.ToJSON()) |
| 13 | + if err != nil { |
| 14 | + return nil, err |
| 15 | + } |
| 16 | + defer response.Body.Close() |
| 17 | + |
| 18 | + body, _ := ioutil.ReadAll(response.Body) |
| 19 | + |
| 20 | + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { |
| 21 | + return nil, errors.New(response.Status) |
| 22 | + } |
| 23 | + |
| 24 | + return VulnerabilityExceptionListFromJSON(body), nil |
| 25 | +} |
| 26 | + |
| 27 | +func (client *sysdigSecureClient) GetVulnerabilityExceptionListByID(ctx context.Context, id string) (*VulnerabilityExceptionList, error) { |
| 28 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodGet, client.getVulnerabilityExceptionListByIDURL(id), nil) |
| 29 | + if err != nil { |
| 30 | + return nil, err |
| 31 | + } |
| 32 | + defer response.Body.Close() |
| 33 | + |
| 34 | + body, _ := ioutil.ReadAll(response.Body) |
| 35 | + |
| 36 | + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { |
| 37 | + return nil, errors.New(response.Status) |
| 38 | + } |
| 39 | + |
| 40 | + return VulnerabilityExceptionListFromJSON(body), nil |
| 41 | +} |
| 42 | + |
| 43 | +func (client *sysdigSecureClient) DeleteVulnerabilityExceptionList(ctx context.Context, id string) error { |
| 44 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodDelete, client.getVulnerabilityExceptionListByIDURL(id), nil) |
| 45 | + if err != nil { |
| 46 | + return err |
| 47 | + } |
| 48 | + defer response.Body.Close() |
| 49 | + |
| 50 | + if response.StatusCode != http.StatusNoContent { |
| 51 | + return errors.New(response.Status) |
| 52 | + } |
| 53 | + |
| 54 | + return nil |
| 55 | +} |
| 56 | + |
| 57 | +func (client *sysdigSecureClient) UpdateVulnerabilityExceptionList(ctx context.Context, list *VulnerabilityExceptionList) (*VulnerabilityExceptionList, error) { |
| 58 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodPut, client.getVulnerabilityExceptionListByIDURL(list.ID), list.ToJSON()) |
| 59 | + if err != nil { |
| 60 | + return nil, err |
| 61 | + } |
| 62 | + defer response.Body.Close() |
| 63 | + |
| 64 | + body, _ := ioutil.ReadAll(response.Body) |
| 65 | + |
| 66 | + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { |
| 67 | + return nil, errors.New(response.Status) |
| 68 | + } |
| 69 | + |
| 70 | + return VulnerabilityExceptionListFromJSON(body), nil |
| 71 | +} |
| 72 | + |
| 73 | +func (client *sysdigSecureClient) CreateVulnerabilityException(ctx context.Context, listID string, exception *VulnerabilityException) (*VulnerabilityException, error) { |
| 74 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodPost, client.getVulnerabilityExceptionURL(listID), exception.ToJSON()) |
| 75 | + if err != nil { |
| 76 | + return nil, err |
| 77 | + } |
| 78 | + defer response.Body.Close() |
| 79 | + |
| 80 | + body, _ := ioutil.ReadAll(response.Body) |
| 81 | + |
| 82 | + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { |
| 83 | + return nil, errors.New(response.Status) |
| 84 | + } |
| 85 | + |
| 86 | + return VulnerabilityExceptionFromJSON(body), nil |
| 87 | +} |
| 88 | + |
| 89 | +func (client *sysdigSecureClient) GetVulnerabilityExceptionByID(ctx context.Context, listID string, exceptionID string) (*VulnerabilityException, error) { |
| 90 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodGet, client.getVulnerabilityExceptionByIDURL(listID, exceptionID), nil) |
| 91 | + if err != nil { |
| 92 | + return nil, err |
| 93 | + } |
| 94 | + defer response.Body.Close() |
| 95 | + |
| 96 | + body, _ := ioutil.ReadAll(response.Body) |
| 97 | + |
| 98 | + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { |
| 99 | + return nil, errors.New(response.Status) |
| 100 | + } |
| 101 | + |
| 102 | + return VulnerabilityExceptionFromJSON(body), nil |
| 103 | +} |
| 104 | + |
| 105 | +func (client *sysdigSecureClient) DeleteVulnerabilityException(ctx context.Context, listID string, exceptionID string) error { |
| 106 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodDelete, client.getVulnerabilityExceptionByIDURL(listID, exceptionID), nil) |
| 107 | + if err != nil { |
| 108 | + return err |
| 109 | + } |
| 110 | + defer response.Body.Close() |
| 111 | + |
| 112 | + if response.StatusCode != http.StatusNoContent { |
| 113 | + return errors.New(response.Status) |
| 114 | + } |
| 115 | + |
| 116 | + return nil |
| 117 | +} |
| 118 | + |
| 119 | +func (client *sysdigSecureClient) UpdateVulnerabilityException(ctx context.Context, listID string, exception *VulnerabilityException) (*VulnerabilityException, error) { |
| 120 | + response, err := client.doSysdigSecureRequest(ctx, http.MethodPut, client.getVulnerabilityExceptionByIDURL(listID, exception.ID), exception.ToJSON()) |
| 121 | + if err != nil { |
| 122 | + return nil, err |
| 123 | + } |
| 124 | + defer response.Body.Close() |
| 125 | + |
| 126 | + body, _ := ioutil.ReadAll(response.Body) |
| 127 | + |
| 128 | + if response.StatusCode != http.StatusOK && response.StatusCode != http.StatusCreated { |
| 129 | + return nil, errors.New(response.Status) |
| 130 | + } |
| 131 | + |
| 132 | + return VulnerabilityExceptionFromJSON(body), nil |
| 133 | +} |
| 134 | + |
| 135 | +func (client *sysdigSecureClient) getVulnerabilityExceptionListURL() string { |
| 136 | + return fmt.Sprintf("%s/api/scanning/v1/vulnexceptions", client.URL) |
| 137 | +} |
| 138 | + |
| 139 | +func (client sysdigSecureClient) getVulnerabilityExceptionListByIDURL(id string) string { |
| 140 | + return fmt.Sprintf("%s/api/scanning/v1/vulnexceptions/%s", client.URL, id) |
| 141 | +} |
| 142 | + |
| 143 | +func (client *sysdigSecureClient) getVulnerabilityExceptionURL(listID string) string { |
| 144 | + return fmt.Sprintf("%s/api/scanning/v1/vulnexceptions/%s/vulnerabilities", client.URL, listID) |
| 145 | +} |
| 146 | + |
| 147 | +func (client *sysdigSecureClient) getVulnerabilityExceptionByIDURL(listID, ID string) string { |
| 148 | + return fmt.Sprintf("%s/api/scanning/v1/vulnexceptions/%s/vulnerabilities/%s/", client.URL, listID, ID) |
| 149 | +} |
0 commit comments