Skip to content

Use http consts for HTTP methods #958

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

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/vulnsrc/rhel/rhel.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var (
)

func httpGet(url string) (*http.Response, error) {
req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clairify/clair/clair.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *Client) analyzeLayer(path, layerName, parentLayerName string, h map[str
}
fullURL := fmt.Sprintf("%v/v1/layers", c.endpoint)
logrus.Debugf("Pushing layer %v to Clair", path)
request, err := http.NewRequest("POST", fullURL, bytes.NewBuffer(jsonPayload))
request, err := http.NewRequest(http.MethodPost, fullURL, bytes.NewBuffer(jsonPayload))
if err != nil {
return err
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c *Client) sendRequest(req *http.Request) ([]byte, int, error) {
// RetrieveLayerData fetches the layer information for the passed layer.
func (c *Client) RetrieveLayerData(layer string, values url.Values) (*v1.LayerEnvelope, bool, error) {
url := fmt.Sprintf("%v/v1/layers/%v", c.endpoint, layer)
request, err := http.NewRequest("GET", url, nil)
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, false, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/clairify/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func encodeValues(opts *types.GetImageDataOpts) url.Values {

// Ping verifies that Clairify is accessible.
func (c *Clairify) Ping() error {
request, err := http.NewRequest("GET", c.endpoint+"/scanner/ping", nil)
request, err := http.NewRequest(http.MethodGet, c.endpoint+"/scanner/ping", nil)
if err != nil {
return err
}
Expand All @@ -131,7 +131,7 @@ func (c *Clairify) AddImage(username, password string, req *types.ImageRequest)
if err != nil {
return nil, err
}
request, err := http.NewRequest("POST", c.endpoint+"/scanner/image", bytes.NewBuffer(data))
request, err := http.NewRequest(http.MethodPost, c.endpoint+"/scanner/image", bytes.NewBuffer(data))
if err != nil {
return nil, err
}
Expand All @@ -151,7 +151,7 @@ func (c *Clairify) AddImage(username, password string, req *types.ImageRequest)
// RetrieveImageDataBySHA contacts Clairify to fetch vulnerability data by the image SHA.
func (c *Clairify) RetrieveImageDataBySHA(sha string, opts *types.GetImageDataOpts) (*v1.LayerEnvelope, error) {
values := encodeValues(opts)
request, err := http.NewRequest("GET", c.endpoint+"/scanner/sha/"+sha, nil)
request, err := http.NewRequest(http.MethodGet, c.endpoint+"/scanner/sha/"+sha, nil)
if err != nil {
return nil, err
}
Expand All @@ -172,7 +172,7 @@ func (c *Clairify) RetrieveImageDataBySHA(sha string, opts *types.GetImageDataOp
func (c *Clairify) RetrieveImageDataByName(image *types.Image, opts *types.GetImageDataOpts) (*v1.LayerEnvelope, error) {
values := encodeValues(opts)
url := fmt.Sprintf("%s/scanner/image/%s/%s/%s", c.endpoint, image.Registry, image.Remote, image.Tag)
request, err := http.NewRequest("GET", url, nil)
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand All @@ -191,7 +191,7 @@ func (c *Clairify) RetrieveImageDataByName(image *types.Image, opts *types.GetIm
// GetVulnDefsMetadata contacts Clairify to fetch vulnerability definitions metadata.
func (c *Clairify) GetVulnDefsMetadata() (*protoV1.VulnDefsMetadata, error) {
url := fmt.Sprintf("%s/scanner/vulndefs/metadata", c.endpoint)
request, err := http.NewRequest("GET", url, nil)
request, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func GetWithUserAgent(url string) (*http.Response, error) {
Transport: proxy.RoundTripper(),
}

req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return nil, err
}
Expand Down