Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
fix: adding missing error checks (#371)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored Dec 15, 2021
1 parent de65cd4 commit 5626bf9
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/api/utils/apiUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (a *APIHandler) DeleteService(project, service string) (*models.DeleteServi
// GetMetadata retrieve keptn MetaData information
func (a *APIHandler) GetMetadata() (*models.Metadata, *models.Error) {
req, err := http.NewRequest("GET", a.Scheme+"://"+a.getBaseURL()+v1MetadataPath, nil)
if err != nil {
return nil, buildErrorResponse(err.Error())
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, a)

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/utils/eventUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func (e *EventHandler) getEvents(uri string, numberOfPages int) ([]*models.Keptn
url.RawQuery = q.Encode()
}
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, buildErrorResponse(err.Error())
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, e)

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/utils/projectUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (p *ProjectHandler) GetAllProjects() ([]*models.Project, error) {
url.RawQuery = q.Encode()
}
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, p)

Expand Down
15 changes: 15 additions & 0 deletions pkg/api/utils/resourceUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ func (r *ResourceHandler) writeResources(uri string, method string, resources []
return "", err
}
req, err := http.NewRequest(method, uri, bytes.NewBuffer(resourceStr))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, r)

Expand Down Expand Up @@ -249,6 +252,9 @@ func (r *ResourceHandler) writeResource(uri string, method string, resource *mod
return "", err
}
req, err := http.NewRequest(method, uri, bytes.NewBuffer(resourceStr))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, r)

Expand Down Expand Up @@ -279,6 +285,9 @@ func (r *ResourceHandler) writeResource(uri string, method string, resource *mod
func (r *ResourceHandler) getResource(uri string) (*models.Resource, error) {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, r)

Expand Down Expand Up @@ -320,6 +329,9 @@ func (r *ResourceHandler) getResource(uri string) (*models.Resource, error) {
func (r *ResourceHandler) deleteResource(uri string) error {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("DELETE", uri, nil)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, r)

Expand Down Expand Up @@ -365,6 +377,9 @@ func (r *ResourceHandler) getAllResources(u *url.URL) ([]*models.Resource, error
u.RawQuery = q.Encode()
}
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, r)

Expand Down
6 changes: 6 additions & 0 deletions pkg/api/utils/serviceUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (s *ServiceHandler) GetService(project, stage, service string) (*models.Ser
return nil, err
}
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, s)

Expand Down Expand Up @@ -153,6 +156,9 @@ func (s *ServiceHandler) GetAllServices(project string, stage string) ([]*models
url.RawQuery = q.Encode()
}
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, s)

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/utils/shipyardControllerUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ func (s *ShipyardControllerHandler) GetOpenTriggeredEvents(filter EventFilter) (
return nil, err
}
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, s)

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/utils/stageUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (s *StageHandler) GetAllStages(project string) ([]*models.Stage, error) {
url.RawQuery = q.Encode()
}
req, err := http.NewRequest("GET", url.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
addAuthHeader(req, s)

Expand Down
3 changes: 3 additions & 0 deletions pkg/lib/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func getLatestEvent(keptnContext string, eventType string, uri string, datastore

http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
return nil, buildErrorResponse(err.Error())
}
req.Header.Set("Content-Type", "application/json")

resp, err := datastore.getHTTPClient().Do(req)
Expand Down

0 comments on commit 5626bf9

Please sign in to comment.