Skip to content

Commit 2bb060b

Browse files
Jeffgolden/ch35161/migrate graphql to vendor api (#181)
* Refactor precommands to avoid graphql * adding v3 app delete * migrating channel, release, and customer functions * adding REST installer calls * removing kots graphql client
1 parent 783bd92 commit 2bb060b

30 files changed

+2799
-501
lines changed

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ publish-pacts:
9797
get-spec-prod:
9898
mkdir -p gen/spec/
9999
curl -o gen/spec/v1.json https://api.replicated.com/vendor/v1/spec/vendor-api.json
100-
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
100+
curl -o gen/spec/v3.json https://api.replicated.com/vendor/v3/spec/vendor-api-v3.json
101101

102102
# generate the swagger specs from the local replicatedcom/vendor-api repo
103103
.PHONY: get-spec-local
@@ -125,14 +125,13 @@ gen-models:
125125
-i /local/gen/spec/v1.json \
126126
-l go \
127127
-o /local/gen/go/v1; \
128-
# TODO this will fail, see note above in get-spec-prod
129128
docker run --rm \
130129
--volume `pwd`:/local \
131130
swaggerapi/swagger-codegen-cli generate \
132131
-Dmodels -DmodelsDocs=false \
133-
-i /local/gen/spec/v2.json \
132+
-i /local/gen/spec/v3.json \
134133
-l go \
135-
-o /local/gen/go/v2;
134+
-o /local/gen/go/v3; \
136135

137136
.PHONY: build
138137
build:

cli/cmd/app_create.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func (r *runners) createApp(_ *cobra.Command, args []string) error {
2929

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

32-
3332
app, err := kotsRestClient.CreateKOTSApp(appName)
3433

3534
if err != nil {
@@ -39,9 +38,9 @@ func (r *runners) createApp(_ *cobra.Command, args []string) error {
3938
apps := []types.AppAndChannels{
4039
{
4140
App: &types.App{
42-
ID: app.ID,
43-
Name: app.Name,
44-
Slug: app.Slug,
41+
ID: app.Id,
42+
Name: app.Name,
43+
Slug: app.Slug,
4544
Scheduler: "kots",
4645
},
4746
},

cli/cmd/app_delete.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (r *runners) deleteApp(_ *cobra.Command, args []string) error {
3737
}
3838
log.FinishSpinner()
3939

40-
apps := []types.AppAndChannels{{ App: app}}
40+
apps := []types.AppAndChannels{{App: app}}
4141

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

58-
5958
log.ActionWithSpinner("Deleting App")
6059
err = r.kotsAPI.DeleteKOTSApp(app.ID)
6160
if err != nil {

cli/cmd/app_ls.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package cmd
22

33
import (
4+
"strings"
5+
46
"github.com/pkg/errors"
57
"github.com/replicatedhq/replicated/cli/print"
68
"github.com/replicatedhq/replicated/pkg/types"
79
"github.com/spf13/cobra"
8-
"strings"
910
)
1011

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

3536
appSearch := args[0]
36-
var apps []types.AppAndChannels
37+
var resultApps []types.AppAndChannels
3738
for _, app := range kotsApps {
3839
if strings.Contains(app.App.ID, appSearch) || strings.Contains(app.App.Slug, appSearch) {
39-
apps = append(apps, app)
40+
resultApps = append(resultApps, app)
4041
}
4142
}
42-
return print.Apps(r.w, apps)
43+
return print.Apps(r.w, resultApps)
4344
}

cli/cmd/root.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ func Execute(rootCmd *cobra.Command, stdin io.Reader, stdout io.Writer, stderr i
218218
shipAPI := shipclient.NewGraphQLClient(graphqlOrigin, apiToken)
219219
runCmds.shipAPI = shipAPI
220220

221-
kotsAPI := kotsclient.NewGraphQLClient(graphqlOrigin, apiToken, kurlDotSHOrigin)
221+
httpClient := platformclient.NewHTTPClient(platformOrigin, apiToken)
222+
kotsAPI := &kotsclient.VendorV3Client{HTTPClient: *httpClient}
222223
runCmds.kotsAPI = kotsAPI
223224

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

238-
appType, err := runCmds.api.GetAppType(appSlugOrID)
239+
app, appType, err := runCmds.api.GetAppType(appSlugOrID)
239240
if err != nil {
240241
return err
241242
}
243+
242244
runCmds.appType = appType
243245

244-
if appType == "platform" {
245-
app, err := runCmds.platformAPI.GetApp(appSlugOrID)
246-
if err != nil {
247-
return err
248-
}
249-
runCmds.appID = app.Id
250-
runCmds.appSlug = app.Slug
251-
} else if appType == "ship" {
252-
app, err := runCmds.shipAPI.GetApp(appSlugOrID)
253-
if err != nil {
254-
return err
255-
}
256-
runCmds.appID = app.ID
257-
runCmds.appSlug = app.Slug
258-
} else if appType == "kots" {
259-
app, err := runCmds.kotsAPI.GetApp(appSlugOrID)
260-
if err != nil {
261-
return err
262-
}
263-
runCmds.appID = app.ID
264-
runCmds.appSlug = app.Slug
265-
}
246+
runCmds.appID = app.ID
247+
runCmds.appSlug = app.Slug
266248

267249
return nil
268250
}
269251

270-
271252
channelCmd.PersistentPreRunE = prerunCommand
272253
releaseCmd.PersistentPreRunE = prerunCommand
273254
collectorsCmd.PersistentPreRunE = prerunCommand

cli/cmd/runner.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/replicatedhq/replicated/pkg/kotsclient"
9-
109
"github.com/replicatedhq/replicated/pkg/shipclient"
1110
"github.com/spf13/cobra"
1211

@@ -26,7 +25,7 @@ type runners struct {
2625
enterpriseClient *enterpriseclient.HTTPClient
2726
platformAPI *platformclient.HTTPClient
2827
shipAPI *shipclient.GraphQLClient
29-
kotsAPI *kotsclient.GraphQLClient
28+
kotsAPI *kotsclient.VendorV3Client
3029
stdin io.Reader
3130
dir string
3231
w *tabwriter.Writer

cli/test/kots_app_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ package test
33
import (
44
"bytes"
55
"fmt"
6+
"io/ioutil"
7+
"os"
8+
"strings"
9+
610
. "github.com/onsi/ginkgo"
711
"github.com/replicatedhq/replicated/cli/cmd"
812
"github.com/replicatedhq/replicated/pkg/kotsclient"
913
"github.com/replicatedhq/replicated/pkg/platformclient"
14+
"github.com/replicatedhq/replicated/pkg/types"
1015
"github.com/stretchr/testify/assert"
11-
"io/ioutil"
12-
"os"
13-
"strings"
1416
)
1517

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

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

26-
var app *kotsclient.KotsApp
27+
var app *types.KotsAppWithChannels
2728
var tmpdir string
2829

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

3839
AfterEach(func() {
39-
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
40+
err := kotsRestClient.DeleteKOTSApp(app.Id)
4041
req.NoError(err)
4142
err = os.RemoveAll(tmpdir)
4243
req.NoError(err)
@@ -73,7 +74,7 @@ var _ = Describe("kots apps", func() {
7374
req.Empty(stderr.String(), "Expected no stderr output")
7475
req.NotEmpty(stdout.String(), "Expected stdout output")
7576

76-
req.Contains(stdout.String(), app.ID)
77+
req.Contains(stdout.String(), app.Id)
7778
req.Contains(stdout.String(), app.Name)
7879
req.Contains(stdout.String(), "kots")
7980
})
@@ -93,15 +94,16 @@ var _ = Describe("kots apps", func() {
9394
req.NotEmpty(stdout.String(), "Expected stdout output")
9495

9596
req.Equal(stdout.String(),
96-
`ID NAME SLUG SCHEDULER
97-
`+ app.ID +` ` + app.Name + ` ` + app.Slug + ` kots
97+
`ID NAME SLUG SCHEDULER
98+
`+app.Id+` `+app.Name+` `+app.Slug+` kots
9899
`)
99100
})
100101
})
101102

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

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

139140
req.NotContains(stdout.String(), appSlug)
140141
req.Equal(stdout.String(),
141-
`ID NAME SLUG SCHEDULER
142+
`ID NAME SLUG SCHEDULER
142143
`)
143144
})
144145
})

cli/test/kots_installer_create_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88

99
"github.com/replicatedhq/replicated/pkg/kotsclient"
10+
"github.com/replicatedhq/replicated/pkg/types"
1011

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

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

27-
var app *kotsclient.KotsApp
27+
var app *types.KotsAppWithChannels
28+
2829
var tmpdir string
2930

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

3940
AfterEach(func() {
40-
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
41+
err := kotsRestClient.DeleteKOTSApp(app.Id)
4142
req.NoError(err)
4243
err = os.RemoveAll(tmpdir)
4344
req.NoError(err)

cli/test/kots_release_create_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package test
22

33
import (
44
"bytes"
5-
"github.com/replicatedhq/replicated/pkg/kotsclient"
65
"io/ioutil"
76
"os"
87
"path/filepath"
98

9+
"github.com/replicatedhq/replicated/pkg/kotsclient"
10+
"github.com/replicatedhq/replicated/pkg/types"
11+
1012
. "github.com/onsi/ginkgo"
1113
"github.com/replicatedhq/replicated/cli/cmd"
1214
"github.com/replicatedhq/replicated/pkg/platformclient"
@@ -21,9 +23,8 @@ var _ = Describe("kots release create", func() {
2123

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

26-
var app *kotsclient.KotsApp
27+
var app *types.KotsAppWithChannels
2728
var tmpdir string
2829

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

3839
AfterEach(func() {
39-
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
40+
err := kotsRestClient.DeleteKOTSApp(app.Id)
4041
req.NoError(err)
4142
err = os.RemoveAll(tmpdir)
4243
req.NoError(err)

cli/test/kots_release_lint_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package test
22

33
import (
44
"bytes"
5-
"github.com/replicatedhq/replicated/pkg/kotsclient"
65
"io/ioutil"
76
"os"
87
"path/filepath"
98

9+
"github.com/replicatedhq/replicated/pkg/kotsclient"
10+
"github.com/replicatedhq/replicated/pkg/types"
11+
1012
. "github.com/onsi/ginkgo"
1113
"github.com/replicatedhq/replicated/cli/cmd"
1214
"github.com/replicatedhq/replicated/pkg/platformclient"
@@ -21,9 +23,8 @@ var _ = Describe("kots release lint", func() {
2123

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

26-
var app *kotsclient.KotsApp
27+
var app *types.KotsAppWithChannels
2728
var tmpdir string
2829

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

3839
AfterEach(func() {
39-
err := kotsGraphqlClient.DeleteKOTSApp(app.ID)
40+
err := kotsRestClient.DeleteKOTSApp(app.Id)
4041
req.NoError(err)
4142
err = os.RemoveAll(tmpdir)
4243
req.NoError(err)

0 commit comments

Comments
 (0)