1
1
package kotsclient
2
2
3
3
import (
4
+ "bytes"
5
+ "compress/gzip"
4
6
"fmt"
7
+ "io"
5
8
"net/http"
9
+ "strings"
6
10
7
11
"github.com/pkg/errors"
8
12
"github.com/replicatedhq/replicated/pkg/graphql"
9
13
"github.com/replicatedhq/replicated/pkg/types"
10
14
)
11
15
12
- type GraphQLResponseKotsCreateRelease struct {
13
- Data KotsCreateReleaseData `json:"data,omitempty"`
14
- Errors []graphql.GQLError `json:"errors,omitempty"`
15
- }
16
-
17
- type KotsCreateReleaseData struct {
18
- KotsReleaseData KotsReleaseSequence `json:"createKotsRelease"`
19
- }
20
-
21
- type KotsReleaseSequence struct {
22
- Sequence int64 `json:"sequence"`
23
- }
24
-
25
- type GraphQLResponseKotsUpdateRelease struct {
26
- Data KotsUpdateReleaseData `json:"data,omitempty"`
27
- Errors []graphql.GQLError `json:"errors,omitempty"`
28
- }
29
-
30
- type KotsUpdateReleaseData struct {
31
- KotsReleaseData KotsReleaseSequence `json:"updateKotsRelease"`
32
- }
33
-
34
16
type GraphQLResponseListReleases struct {
35
17
Data * KotsReleasesData `json:"data,omitempty"`
36
18
Errors []graphql.GQLError `json:"errors,omitempty"`
@@ -48,72 +30,60 @@ type KotsRelease struct {
48
30
Channels []* KotsChannel `json:"channels"`
49
31
}
50
32
51
- type GraphQLResponseUpdateKotsRelease struct {
52
- Data * KotsReleaseUpdateData `json:"data,omitempty"`
53
- }
54
-
55
- type KotsReleaseUpdateData struct {
56
- UpdateKotsRelease * UpdateKotsRelease `json:"updateKotsRelease"`
57
- }
58
-
59
- type UpdateKotsRelease struct {
60
- ID string `json:"id"`
61
- Config string `json:"spec,omitempty"`
62
- }
63
-
64
- const createReleaseQuery = `
65
- mutation createKotsRelease($appId: ID!, $spec: String) {
66
- createKotsRelease(appId: $appId, spec: $spec) {
67
- sequence
33
+ func (c * VendorV3Client ) CreateRelease (appID string , multiyaml string ) (* types.ReleaseInfo , error ) {
34
+ gzipData := bytes .NewBuffer (nil )
35
+ gzipWriter := gzip .NewWriter (gzipData )
36
+ _ , err := io .Copy (gzipWriter , strings .NewReader (multiyaml ))
37
+ if err != nil {
38
+ gzipWriter .Close ()
39
+ return nil , errors .Wrap (err , "failed to write gzip data" )
68
40
}
69
- }`
70
41
71
- func (c * GraphQLClient ) CreateRelease (appID string , multiyaml string ) (* types.ReleaseInfo , error ) {
72
- response := GraphQLResponseKotsCreateRelease {}
42
+ if err := gzipWriter .Close (); err != nil {
43
+ return nil , errors .Wrap (err , "failed to close gzip writer" )
44
+ }
73
45
74
- request := graphql.Request {
75
- Query : createReleaseQuery ,
76
- Variables : map [string ]interface {}{
77
- "appId" : appID ,
78
- "spec" : multiyaml ,
79
- },
46
+ request := types.KotsCreateReleaseRequest {
47
+ SpecGzip : gzipData .Bytes (),
80
48
}
81
49
82
- if err := c .ExecuteRequest (request , & response ); err != nil {
83
- return nil , err
50
+ response := types.KotsGetReleaseResponse {}
51
+
52
+ url := fmt .Sprintf ("/v3/app/%s/release" , appID )
53
+ err = c .DoJSON ("POST" , url , http .StatusCreated , request , & response )
54
+ if err != nil {
55
+ return nil , errors .Wrap (err , "failed to create release" )
84
56
}
85
57
86
58
releaseInfo := types.ReleaseInfo {
87
- AppID : appID ,
88
- Sequence : response .Data . KotsReleaseData .Sequence ,
59
+ AppID : response . Release . AppID ,
60
+ Sequence : response .Release .Sequence ,
89
61
}
90
62
91
63
return & releaseInfo , nil
92
64
}
93
65
94
- const updateKotsRelease = `
95
- mutation updateKotsRelease($appId: ID!, $spec: String!, $sequence: Int) {
96
- updateKotsRelease(appId: $appId, spec: $spec, sequence: $sequence) {
97
- sequence
98
- }
99
- }
100
- `
101
-
102
- func (c * GraphQLClient ) UpdateRelease (appID string , sequence int64 , multiyaml string ) error {
103
- response := GraphQLResponseUpdateKotsRelease {}
66
+ func (c * VendorV3Client ) UpdateRelease (appID string , sequence int64 , multiyaml string ) error {
67
+ gzipData := bytes .NewBuffer (nil )
68
+ gzipWriter := gzip .NewWriter (gzipData )
69
+ _ , err := io .Copy (gzipWriter , strings .NewReader (multiyaml ))
70
+ if err != nil {
71
+ gzipWriter .Close ()
72
+ return errors .Wrap (err , "failed to write gzip data" )
73
+ }
104
74
105
- request := graphql.Request {
106
- Query : updateKotsRelease ,
75
+ if err := gzipWriter .Close (); err != nil {
76
+ return errors .Wrap (err , "failed to close gzip writer" )
77
+ }
107
78
108
- Variables : map [string ]interface {}{
109
- "appId" : appID ,
110
- "spec" : multiyaml ,
111
- "sequence" : sequence ,
112
- },
79
+ request := types.KotsUpdateReleaseRequest {
80
+ SpecGzip : gzipData .Bytes (),
113
81
}
114
82
115
- if err := c .ExecuteRequest (request , & response ); err != nil {
116
- return err
83
+ url := fmt .Sprintf ("/v3/app/%s/release/%d" , appID , sequence )
84
+ err = c .DoJSON ("PUT" , url , http .StatusOK , request , nil )
85
+ if err != nil {
86
+ return errors .Wrap (err , "failed to create release" )
117
87
}
118
88
119
89
return nil
@@ -124,7 +94,7 @@ func (c *VendorV3Client) ListReleases(appID string) ([]types.ReleaseInfo, error)
124
94
done := false
125
95
page := 0
126
96
for ! done {
127
- resp := types.ListReleasesResponse {}
97
+ resp := types.KotsListReleasesResponse {}
128
98
path := fmt .Sprintf ("/v3/app/%s/releases?currentPage=%d&pageSize=20" , appID , page )
129
99
err := c .DoJSON ("GET" , path , http .StatusOK , nil , & resp )
130
100
if err != nil {
0 commit comments