Skip to content

Commit

Permalink
Jeffgolden/ch35161/migrate graphql to vendor api (#181)
Browse files Browse the repository at this point in the history
* Refactor precommands to avoid graphql

* adding v3 app delete

* migrating channel, release, and customer functions

* adding REST installer calls

* removing kots graphql client
  • Loading branch information
jeffreygolden authored Aug 20, 2021
1 parent 783bd92 commit 2bb060b
Show file tree
Hide file tree
Showing 30 changed files with 2,799 additions and 501 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ publish-pacts:
get-spec-prod:
mkdir -p gen/spec/
curl -o gen/spec/v1.json https://api.replicated.com/vendor/v1/spec/vendor-api.json
curl -o gen/spec/v2.json https://api.replicated.com/vendor/v2/spec/swagger.json; # TODO this is still wrong, need to find where this is hosted
curl -o gen/spec/v3.json https://api.replicated.com/vendor/v3/spec/vendor-api-v3.json

# generate the swagger specs from the local replicatedcom/vendor-api repo
.PHONY: get-spec-local
Expand Down Expand Up @@ -125,14 +125,13 @@ gen-models:
-i /local/gen/spec/v1.json \
-l go \
-o /local/gen/go/v1; \
# TODO this will fail, see note above in get-spec-prod
docker run --rm \
--volume `pwd`:/local \
swaggerapi/swagger-codegen-cli generate \
-Dmodels -DmodelsDocs=false \
-i /local/gen/spec/v2.json \
-i /local/gen/spec/v3.json \
-l go \
-o /local/gen/go/v2;
-o /local/gen/go/v3; \

.PHONY: build
build:
Expand Down
7 changes: 3 additions & 4 deletions cli/cmd/app_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (r *runners) createApp(_ *cobra.Command, args []string) error {

kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *r.platformAPI}


app, err := kotsRestClient.CreateKOTSApp(appName)

if err != nil {
Expand All @@ -39,9 +38,9 @@ func (r *runners) createApp(_ *cobra.Command, args []string) error {
apps := []types.AppAndChannels{
{
App: &types.App{
ID: app.ID,
Name: app.Name,
Slug: app.Slug,
ID: app.Id,
Name: app.Name,
Slug: app.Slug,
Scheduler: "kots",
},
},
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/app_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (r *runners) deleteApp(_ *cobra.Command, args []string) error {
}
log.FinishSpinner()

apps := []types.AppAndChannels{{ App: app}}
apps := []types.AppAndChannels{{App: app}}

err = print.Apps(r.w, apps)
if err != nil {
Expand All @@ -55,7 +55,6 @@ func (r *runners) deleteApp(_ *cobra.Command, args []string) error {
}
}


log.ActionWithSpinner("Deleting App")
err = r.kotsAPI.DeleteKOTSApp(app.ID)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cli/cmd/app_ls.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cmd

import (
"strings"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
"strings"
)

func (r *runners) InitAppList(parent *cobra.Command) *cobra.Command {
Expand Down Expand Up @@ -33,11 +34,11 @@ func (r *runners) listApps(_ *cobra.Command, args []string) error {
}

appSearch := args[0]
var apps []types.AppAndChannels
var resultApps []types.AppAndChannels
for _, app := range kotsApps {
if strings.Contains(app.App.ID, appSearch) || strings.Contains(app.App.Slug, appSearch) {
apps = append(apps, app)
resultApps = append(resultApps, app)
}
}
return print.Apps(r.w, apps)
return print.Apps(r.w, resultApps)
}
31 changes: 6 additions & 25 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
shipAPI := shipclient.NewGraphQLClient(graphqlOrigin, apiToken)
runCmds.shipAPI = shipAPI

kotsAPI := kotsclient.NewGraphQLClient(graphqlOrigin, apiToken, kurlDotSHOrigin)
httpClient := platformclient.NewHTTPClient(platformOrigin, apiToken)
kotsAPI := &kotsclient.VendorV3Client{HTTPClient: *httpClient}
runCmds.kotsAPI = kotsAPI

commonAPI := client.NewClient(platformOrigin, graphqlOrigin, apiToken, kurlDotSHOrigin)
Expand All @@ -235,39 +236,19 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
appSlugOrID = os.Getenv("REPLICATED_APP")
}

appType, err := runCmds.api.GetAppType(appSlugOrID)
app, appType, err := runCmds.api.GetAppType(appSlugOrID)
if err != nil {
return err
}

runCmds.appType = appType

if appType == "platform" {
app, err := runCmds.platformAPI.GetApp(appSlugOrID)
if err != nil {
return err
}
runCmds.appID = app.Id
runCmds.appSlug = app.Slug
} else if appType == "ship" {
app, err := runCmds.shipAPI.GetApp(appSlugOrID)
if err != nil {
return err
}
runCmds.appID = app.ID
runCmds.appSlug = app.Slug
} else if appType == "kots" {
app, err := runCmds.kotsAPI.GetApp(appSlugOrID)
if err != nil {
return err
}
runCmds.appID = app.ID
runCmds.appSlug = app.Slug
}
runCmds.appID = app.ID
runCmds.appSlug = app.Slug

return nil
}


channelCmd.PersistentPreRunE = prerunCommand
releaseCmd.PersistentPreRunE = prerunCommand
collectorsCmd.PersistentPreRunE = prerunCommand
Expand Down
3 changes: 1 addition & 2 deletions cli/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/replicatedhq/replicated/pkg/kotsclient"

"github.com/replicatedhq/replicated/pkg/shipclient"
"github.com/spf13/cobra"

Expand All @@ -26,7 +25,7 @@ type runners struct {
enterpriseClient *enterpriseclient.HTTPClient
platformAPI *platformclient.HTTPClient
shipAPI *shipclient.GraphQLClient
kotsAPI *kotsclient.GraphQLClient
kotsAPI *kotsclient.VendorV3Client
stdin io.Reader
dir string
w *tabwriter.Writer
Expand Down
23 changes: 12 additions & 11 deletions cli/test/kots_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"strings"

. "github.com/onsi/ginkgo"
"github.com/replicatedhq/replicated/cli/cmd"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"strings"
)

var _ = Describe("kots apps", func() {
Expand All @@ -21,9 +23,8 @@ var _ = Describe("kots apps", func() {

httpClient := platformclient.NewHTTPClient(params.APIOrigin, params.APIToken)
kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *httpClient}
kotsGraphqlClient := kotsclient.NewGraphQLClient(params.GraphqlOrigin, params.APIToken, params.KurlOrigin)

var app *kotsclient.KotsApp
var app *types.KotsAppWithChannels
var tmpdir string

BeforeEach(func() {
Expand All @@ -36,7 +37,7 @@ var _ = Describe("kots apps", func() {
})

AfterEach(func() {
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
err := kotsRestClient.DeleteKOTSApp(app.Id)
req.NoError(err)
err = os.RemoveAll(tmpdir)
req.NoError(err)
Expand Down Expand Up @@ -73,7 +74,7 @@ var _ = Describe("kots apps", func() {
req.Empty(stderr.String(), "Expected no stderr output")
req.NotEmpty(stdout.String(), "Expected stdout output")

req.Contains(stdout.String(), app.ID)
req.Contains(stdout.String(), app.Id)
req.Contains(stdout.String(), app.Name)
req.Contains(stdout.String(), "kots")
})
Expand All @@ -93,15 +94,16 @@ var _ = Describe("kots apps", func() {
req.NotEmpty(stdout.String(), "Expected stdout output")

req.Equal(stdout.String(),
`ID NAME SLUG SCHEDULER
`+ app.ID +` ` + app.Name + ` ` + app.Slug + ` kots
`ID NAME SLUG SCHEDULER
`+app.Id+` `+app.Name+` `+app.Slug+` kots
`)
})
})

Context("replicated app delete", func() {
It("should delete an app", func() {
newName := mustToken(8)
// this test is fragile - if the first character ends up as - , it assumes the token is a flag and fails
newName = strings.ReplaceAll(newName, "_", "-")
newName = strings.ReplaceAll(newName, "=", "-")
var stdout bytes.Buffer
Expand All @@ -120,7 +122,6 @@ var _ = Describe("kots apps", func() {
req.Contains(stdout.String(), appSlug)
req.Contains(stdout.String(), "kots")


stdout.Truncate(0)
rootCmd = cmd.GetRootCmd()
rootCmd.SetArgs([]string{"app", "delete", appSlug, "--force"})
Expand All @@ -138,7 +139,7 @@ var _ = Describe("kots apps", func() {

req.NotContains(stdout.String(), appSlug)
req.Equal(stdout.String(),
`ID NAME SLUG SCHEDULER
`ID NAME SLUG SCHEDULER
`)
})
})
Expand Down
7 changes: 4 additions & 3 deletions cli/test/kots_installer_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/types"

. "github.com/onsi/ginkgo"
"github.com/replicatedhq/replicated/cli/cmd"
Expand All @@ -22,9 +23,9 @@ var _ = Describe("kots installer create", func() {

httpClient := platformclient.NewHTTPClient(params.APIOrigin, params.APIToken)
kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *httpClient}
kotsGraphqlClient := kotsclient.NewGraphQLClient(params.GraphqlOrigin, params.APIToken, params.KurlOrigin)

var app *kotsclient.KotsApp
var app *types.KotsAppWithChannels

var tmpdir string

BeforeEach(func() {
Expand All @@ -37,7 +38,7 @@ var _ = Describe("kots installer create", func() {
})

AfterEach(func() {
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
err := kotsRestClient.DeleteKOTSApp(app.Id)
req.NoError(err)
err = os.RemoveAll(tmpdir)
req.NoError(err)
Expand Down
9 changes: 5 additions & 4 deletions cli/test/kots_release_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package test

import (
"bytes"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"io/ioutil"
"os"
"path/filepath"

"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/types"

. "github.com/onsi/ginkgo"
"github.com/replicatedhq/replicated/cli/cmd"
"github.com/replicatedhq/replicated/pkg/platformclient"
Expand All @@ -21,9 +23,8 @@ var _ = Describe("kots release create", func() {

httpClient := platformclient.NewHTTPClient(params.APIOrigin, params.APIToken)
kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *httpClient}
kotsGraphqlClient := kotsclient.NewGraphQLClient(params.GraphqlOrigin, params.APIToken, params.KurlOrigin)

var app *kotsclient.KotsApp
var app *types.KotsAppWithChannels
var tmpdir string

BeforeEach(func() {
Expand All @@ -36,7 +37,7 @@ var _ = Describe("kots release create", func() {
})

AfterEach(func() {
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
err := kotsRestClient.DeleteKOTSApp(app.Id)
req.NoError(err)
err = os.RemoveAll(tmpdir)
req.NoError(err)
Expand Down
9 changes: 5 additions & 4 deletions cli/test/kots_release_lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package test

import (
"bytes"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"io/ioutil"
"os"
"path/filepath"

"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/types"

. "github.com/onsi/ginkgo"
"github.com/replicatedhq/replicated/cli/cmd"
"github.com/replicatedhq/replicated/pkg/platformclient"
Expand All @@ -21,9 +23,8 @@ var _ = Describe("kots release lint", func() {

httpClient := platformclient.NewHTTPClient(params.APIOrigin, params.APIToken)
kotsRestClient := kotsclient.VendorV3Client{HTTPClient: *httpClient}
kotsGraphqlClient := kotsclient.NewGraphQLClient(params.GraphqlOrigin, params.APIToken, params.KurlOrigin)

var app *kotsclient.KotsApp
var app *types.KotsAppWithChannels
var tmpdir string

BeforeEach(func() {
Expand All @@ -36,7 +37,7 @@ var _ = Describe("kots release lint", func() {
})

AfterEach(func() {
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
err := kotsRestClient.DeleteKOTSApp(app.Id)
req.NoError(err)
err = os.RemoveAll(tmpdir)
req.NoError(err)
Expand Down
6 changes: 3 additions & 3 deletions client/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ func (c *Client) ListApps() ([]types.AppAndChannels, error) {
return nil, err
}

apps := make([]types.AppAndChannels, 0, 0)
apps := make([]types.AppAndChannels, 0)
for _, platformApp := range platformApps {
channels := make([]types.Channel, 0, 0)
channels := make([]types.Channel, 0)
for _, platformChannel := range platformApp.Channels {
channel := types.Channel{
ID: platformChannel.Id,
Expand All @@ -38,7 +38,7 @@ func (c *Client) ListApps() ([]types.AppAndChannels, error) {
ID: platformApp.App.Id,
Name: platformApp.App.Name,
Scheduler: platformApp.App.Scheduler,
Slug: platformApp.App.Scheduler,
Slug: platformApp.App.Slug,
},
Channels: channels,
}
Expand Down
Loading

0 comments on commit 2bb060b

Please sign in to comment.