Skip to content

Commit

Permalink
Merge pull request #165 from replicatedhq/laverya/platform-not-gql-ch…
Browse files Browse the repository at this point in the history
…annel-by-name

platform channel search returns ErrNotFound if not found, not gql error string
  • Loading branch information
laverya authored Nov 30, 2020
2 parents 3ee687a + d49fc7f commit 926821d
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions cli/cmd/collector_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ func (r *runners) collectorUpdate(cmd *cobra.Command, args []string) error {
if r.args.updateCollectorYaml != "" {
_, err := r.api.UpdateCollector(r.appID, specID, r.args.updateCollectorYaml)
if err != nil {
return fmt.Errorf("Failure setting updates for collector: %v", err)
return fmt.Errorf("Failure setting updates for collector: %w", err)
}
}

if r.args.updateCollectorName != "" {
_, err := r.api.UpdateCollectorName(r.appID, specID, r.args.updateCollectorName)
if err != nil {
return fmt.Errorf("Failure setting new yaml config for collector: %v", err)
return fmt.Errorf("Failure setting new yaml config for collector: %w", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/release_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *runners) releaseUpdate(cmd *cobra.Command, args []string) error {
}
}
if err := r.api.UpdateRelease(r.appID, r.appType, seq, r.args.updateReleaseYaml); err != nil {
return fmt.Errorf("Failure setting new yaml config for release: %v", err)
return fmt.Errorf("Failure setting new yaml config for release: %w", err)
}

// ignore the error since operation was successful
Expand Down
3 changes: 2 additions & 1 deletion client/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/pkg/errors"
channels "github.com/replicatedhq/replicated/gen/go/v1"
"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/replicatedhq/replicated/pkg/types"
)

Expand Down Expand Up @@ -100,7 +101,7 @@ func (c *Client) GetOrCreateChannelByName(appID string, appType string, appSlug
ReleaseSequence: channel.ReleaseSequence,
ReleaseLabel: channel.ReleaseLabel,
}, nil
} else if !strings.Contains(err.Error(), gqlNotFoundErr) {
} else if !strings.Contains(err.Error(), gqlNotFoundErr) && !errors.Is(err, platformclient.ErrNotFound) {
return nil, errors.Wrap(err, "get channel")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/enterpriseclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (c *HTTPClient) doJSON(method, path string, successStatus int, reqBody inte
}
if respBody != nil {
if err := json.NewDecoder(resp.Body).Decode(respBody); err != nil {
return fmt.Errorf("%s %s response decoding: %v", method, endpoint, err)
return fmt.Errorf("%s %s response decoding: %w", method, endpoint, err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/platformclient/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (c *HTTPClient) ListApps() ([]apps.AppAndChannels, error) {
func (c *HTTPClient) GetApp(slugOrID string) (*apps.App, error) {
appsAndChannels, err := c.ListApps()
if err != nil {
return nil, fmt.Errorf("GetApp: %v", err)
return nil, fmt.Errorf("GetApp: %w", err)
}
for _, ac := range appsAndChannels {
if ac.App.Slug == slugOrID || ac.App.Id == slugOrID {
Expand Down Expand Up @@ -53,7 +53,7 @@ func (c *HTTPClient) DeleteApp(id string) error {
req.Header.Add("Authorization", c.apiKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("DeleteApp (%s %s): %v", req.Method, endpoint, err)
return fmt.Errorf("DeleteApp (%s %s): %w", req.Method, endpoint, err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
Expand Down
8 changes: 4 additions & 4 deletions pkg/platformclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (c *HTTPClient) ListChannels(appID string) ([]channels.AppChannel, error) {
appChannels := make([]channels.AppChannel, 0)
err := c.DoJSON("GET", path, http.StatusOK, nil, &appChannels)
if err != nil {
return nil, fmt.Errorf("ListChannels: %v", err)
return nil, fmt.Errorf("ListChannels: %w", err)
}
sort.Sort(AppChannels(appChannels))

Expand All @@ -46,7 +46,7 @@ func (c *HTTPClient) CreateChannel(appID string, name string, description string
appChannels := make([]channels.AppChannel, 0)
err := c.DoJSON("POST", path, http.StatusOK, body, &appChannels)
if err != nil {
return fmt.Errorf("CreateChannel: %v", err)
return fmt.Errorf("CreateChannel: %w", err)
}
return nil
}
Expand All @@ -61,7 +61,7 @@ func (c *HTTPClient) ArchiveChannel(appID, channelID string) error {
req.Header.Add("Authorization", c.apiKey)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("ArchiveChannel (%s %s): %v", req.Method, endpoint, err)
return fmt.Errorf("ArchiveChannel (%s %s): %w", req.Method, endpoint, err)
}
resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
Expand Down Expand Up @@ -94,7 +94,7 @@ func (c *HTTPClient) GetChannel(appID, channelID string) (*channels.AppChannel,
respBody := channels.GetChannelInlineResponse200{}
err := c.DoJSON("GET", path, http.StatusOK, nil, &respBody)
if err != nil {
return nil, nil, fmt.Errorf("GetChannel: %v", err)
return nil, nil, fmt.Errorf("GetChannel: %w", err)
}
sort.Sort(ChannelReleases(respBody.Releases))
return respBody.Channel, respBody.Releases, nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/platformclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"net/http"

"github.com/pkg/errors"
)

const apiOrigin = "https://api.replicated.com/vendor"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (c *HTTPClient) DoJSON(method, path string, successStatus int, reqBody, res
return errors.Wrap(err, "read body")
}
if err := json.NewDecoder(bytes.NewReader(bodyBytes)).Decode(respBody); err != nil {
return fmt.Errorf("%s %s response decoding: %v", method, endpoint, err)
return fmt.Errorf("%s %s response decoding: %w", method, endpoint, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/platformclient/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (c *HTTPClient) PromoteCollector(appID string, specID string, channelIDs ..
ChannelIDs: channelIDs,
}
if err := c.DoJSON("POST", path, http.StatusOK, body, nil); err != nil {
return fmt.Errorf("PromoteCollector: %v", err)
return fmt.Errorf("PromoteCollector: %w", err)
}
return nil
}
2 changes: 1 addition & 1 deletion pkg/platformclient/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
)

// ErrNotFound represnets a 404 response from the API.
// ErrNotFound represents a 404 response from the API.
var ErrNotFound = errors.New("Not found")

// BadRequest represents a 400 response from the API.
Expand Down
2 changes: 1 addition & 1 deletion pkg/platformclient/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (c *HTTPClient) CreateLicense(license *v2.LicenseV2) (*v2.LicenseV2, error) {
created := &v2.LicenseV2{}
if err := c.DoJSON("POST", "/v2/license", http.StatusCreated, license, created); err != nil {
return nil, fmt.Errorf("CreateLicense: %v", err)
return nil, fmt.Errorf("CreateLicense: %w", err)
}
return created, nil
}
12 changes: 6 additions & 6 deletions pkg/platformclient/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (c *HTTPClient) ListReleases(appID string) ([]releases.AppReleaseInfo, erro
path := fmt.Sprintf("/v1/app/%s/releases", appID)
releases := make([]releases.AppReleaseInfo, 0)
if err := c.DoJSON("GET", path, http.StatusOK, nil, &releases); err != nil {
return nil, fmt.Errorf("ListReleases: %v", err)
return nil, fmt.Errorf("ListReleases: %w", err)
}
return releases, nil
}
Expand All @@ -28,12 +28,12 @@ func (c *HTTPClient) CreateRelease(appID string, yaml string) (*releases.AppRele
}
release := &releases.AppReleaseInfo{}
if err := c.DoJSON("POST", path, http.StatusCreated, body, release); err != nil {
return nil, fmt.Errorf("CreateRelease: %v", err)
return nil, fmt.Errorf("CreateRelease: %w", err)
}
// API does not accept yaml in create operation, so first create then udpate
if yaml != "" {
if err := c.UpdateRelease(appID, release.Sequence, yaml); err != nil {
return nil, fmt.Errorf("CreateRelease with YAML: %v", err)
return nil, fmt.Errorf("CreateRelease with YAML: %w", err)
}
}
return release, nil
Expand All @@ -50,7 +50,7 @@ func (c *HTTPClient) UpdateRelease(appID string, sequence int64, yaml string) er
req.Header.Set("Content-Type", "application/yaml")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return fmt.Errorf("UpdateRelease: %v", err)
return fmt.Errorf("UpdateRelease: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
Expand All @@ -67,7 +67,7 @@ func (c *HTTPClient) GetRelease(appID string, sequence int64) (*releases.AppRele
path := fmt.Sprintf("/v1/app/%s/%d/properties", appID, sequence)
release := &releases.AppRelease{}
if err := c.DoJSON("GET", path, http.StatusOK, nil, release); err != nil {
return nil, fmt.Errorf("GetRelease: %v", err)
return nil, fmt.Errorf("GetRelease: %w", err)
}
return release, nil
}
Expand All @@ -82,7 +82,7 @@ func (c *HTTPClient) PromoteRelease(appID string, sequence int64, label, notes s
Channels: channelIDs,
}
if err := c.DoJSON("POST", path, http.StatusNoContent, body, nil); err != nil {
return fmt.Errorf("PromoteRelease: %v", err)
return fmt.Errorf("PromoteRelease: %w", err)
}
return nil
}
Expand Down

0 comments on commit 926821d

Please sign in to comment.