-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmarketplace_application.go
321 lines (268 loc) · 13 KB
/
marketplace_application.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
package gsclient
import (
"context"
"errors"
"net/http"
"path"
)
// MarketplaceApplicationOperator aprovides an interface for operations on marketplace applications.
type MarketplaceApplicationOperator interface {
GetMarketplaceApplicationList(ctx context.Context) ([]MarketplaceApplication, error)
GetMarketplaceApplication(ctx context.Context, id string) (MarketplaceApplication, error)
CreateMarketplaceApplication(ctx context.Context, body MarketplaceApplicationCreateRequest) (MarketplaceApplicationCreateResponse, error)
ImportMarketplaceApplication(ctx context.Context, body MarketplaceApplicationImportRequest) (MarketplaceApplicationCreateResponse, error)
UpdateMarketplaceApplication(ctx context.Context, id string, body MarketplaceApplicationUpdateRequest) error
DeleteMarketplaceApplication(ctx context.Context, id string) error
GetMarketplaceApplicationEventList(ctx context.Context, id string) ([]Event, error)
}
// MarketplaceApplicationList holds a list of market applications.
type MarketplaceApplicationList struct {
// Array of market applications.
List map[string]MarketplaceApplicationProperties `json:"applications"`
}
// MarketplaceApplication represent a single market application.
type MarketplaceApplication struct {
// Properties of a market application.
Properties MarketplaceApplicationProperties `json:"application"`
}
// MarketplaceApplicationProperties holds properties of a market application.
type MarketplaceApplicationProperties struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Unique hash to allow user to import the self-created marketplace application.
UniqueHash string `json:"unique_hash"`
// Path to the images of the application.
ObjectStoragePath string `json:"object_storage_path"`
// Whether the you are the owner of application or not.
IsApplicationOwner bool `json:"application_owner"`
// Setup of the application.
Setup MarketplaceApplicationSetup `json:"setup"`
// Whether the template is published by the partner to their tenant.
Published bool `json:"published"`
// The date when the template is published into other tenant in the same partner.
PublishedDate GSTime `json:"published_date"`
// Whether the tenants want their template to be published or not.
PublishRequested bool `json:"publish_requested"`
// The date when the tenant requested their template to be published.
PublishRequestedDate GSTime `json:"publish_requested_date"`
// Whether a partner wants their tenant template published to other partners.
PublishGlobalRequested bool `json:"publish_global_requested"`
// The date when a partner requested their tenants template to be published.
PublishGlobalRequestedDate GSTime `json:"publish_global_requested_date"`
// Whether a template is published to other partner or not.
PublishedGlobal bool `json:"published_global"`
// The date when a template is published to other partner.
PublishedGlobalDate GSTime `json:"published_global_date"`
// Enum:"CMS", "project management", "Adminpanel", "Collaboration", "Cloud Storage", "Archiving".
// Category of marketplace application.
Category string `json:"category"`
// Metadata of the Application.
Metadata MarketplaceApplicationMetadata `json:"metadata"`
// Defines the date and time of the last object change.
ChangeTime GSTime `json:"change_time"`
// Defines the date and time the object was initially created.
CreateTime GSTime `json:"create_time"`
// The UUID of an object is always unique, and refers to a specific object.
ObjectUUID string `json:"object_uuid"`
// Status indicates the status of the object.
Status string `json:"status"`
// The type of template.
ApplicationType string `json:"application_type"`
}
// MarketplaceApplicationSetup represents marketplace application's setup.
type MarketplaceApplicationSetup struct {
// Number of server cores.
Cores int `json:"cores"`
// The capacity of server memory in GB.
Memory int `json:"memory"`
// The capacity of a storage in GB.
Capacity int `json:"capacity"`
}
// MarketplaceApplicationMetadata holds metadata of a marketplace application.
type MarketplaceApplicationMetadata struct {
License string `json:"license"`
OS string `json:"os"`
Components []string `json:"components"`
Overview string `json:"overview"`
Hints string `json:"hints"`
Icon string `json:"icon"`
Features string `json:"features"`
TermsOfUse string `json:"terms_of_use"`
Author string `json:"author"`
Advices string `json:"advices"`
}
// MarketplaceApplicationCreateRequest represents a request for creating a marketplace application.
type MarketplaceApplicationCreateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters.
Name string `json:"name"`
// Path to the images for the application, must be in .gz format and started with "s3//"".
ObjectStoragePath string `json:"object_storage_path"`
// Category of the marketplace application. Allowed values: not-set, MarketplaceApplicationCMSCategory, MarketplaceApplicationProjectManagementCategory, MarketplaceApplicationAdminpanelCategory,
// MarketplaceApplicationCollaborationCategory, MarketplaceApplicationCloudStorageCategory, MarketplaceApplicationArchivingCategory. Optional.
Category MarketplaceApplicationCategory `json:"category,omitempty"`
// whether you want to publish your application or not. Optional.
Publish *bool `json:"publish,omitempty"`
// Application's setup, consist the number of resource for creating the application.
Setup MarketplaceApplicationSetup `json:"setup"`
// Metadata of application.
Metadata *MarketplaceApplicationMetadata `json:"metadata,omitempty"`
}
// MarketplaceApplicationImportRequest represents a request for importing a marketplace application.
type MarketplaceApplicationImportRequest struct {
// Unique hash for importing this marketplace application.
UniqueHash string `json:"unique_hash"`
}
// MarketplaceApplicationCreateResponse represents a response for a marketplace application's creation.
type MarketplaceApplicationCreateResponse struct {
// UUID of the object being created.
ObjectUUID string `json:"object_uuid"`
// UUID of the request.
RequestUUID string `json:"request_uuid"`
// Unique hash for importing this marketplace application.
UniqueHash string `json:"unique_hash"`
}
// MarketplaceApplicationUpdateRequest represents a request for updating a marketplace application.
type MarketplaceApplicationUpdateRequest struct {
// The human-readable name of the object. It supports the full UTF-8 character set, with a maximum of 64 characters. Optional.
Name string `json:"name,omitempty"`
// Path to the images for the application, must be in .gz format and started with s3// . Optional.
ObjectStoragePath string `json:"object_storage_path,omitempty"`
// Category of the marketplace application. Allowed values: not-set, MarketplaceApplicationCMSCategory, MarketplaceApplicationProjectManagementCategory, MarketplaceApplicationAdminpanelCategory,
// MarketplaceApplicationCollaborationCategory, MarketplaceApplicationCloudStorageCategory, MarketplaceApplicationArchivingCategory. Optional.
Category MarketplaceApplicationCategory `json:"category,omitempty"`
// Whether you want to publish your application or not. Optional.
Publish *bool `json:"publish,omitempty"`
// Application's setup, consist the number of resource for creating the application.
Setup *MarketplaceApplicationSetup `json:"setup,omitempty"`
// Metadata of application.
Metadata *MarketplaceApplicationMetadata `json:"metadata,omitempty"`
}
// MarketplaceApplicationCategory represents the category in which a market application is.
type MarketplaceApplicationCategory string
// All allowed Marketplace application category's values.
var (
MarketplaceApplicationCMSCategory MarketplaceApplicationCategory = "CMS"
MarketplaceApplicationProjectManagementCategory MarketplaceApplicationCategory = "project management"
MarketplaceApplicationAdminpanelCategory MarketplaceApplicationCategory = "Adminpanel"
MarketplaceApplicationCollaborationCategory MarketplaceApplicationCategory = "Collaboration"
MarketplaceApplicationCloudStorageCategory MarketplaceApplicationCategory = "Cloud Storage"
MarketplaceApplicationArchivingCategory MarketplaceApplicationCategory = "Archiving"
)
// GetMarketplaceApplicationList gets a list of available marketplace applications.
//
// See: https://gridscale.io/en//api-documentation/index.html#operation/getMarketplaceApplications
func (c *Client) GetMarketplaceApplicationList(ctx context.Context) ([]MarketplaceApplication, error) {
r := gsRequest{
uri: apiMarketplaceApplicationBase,
method: http.MethodGet,
skipCheckingRequest: true,
}
var response MarketplaceApplicationList
var marketApps []MarketplaceApplication
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
marketApps = append(marketApps, MarketplaceApplication{
Properties: properties,
})
}
return marketApps, err
}
// GetMarketplaceApplication gets a marketplace application.
//
// See https://gridscale.io/en//api-documentation/index.html#operation/getMarketplaceApplication
func (c *Client) GetMarketplaceApplication(ctx context.Context, id string) (MarketplaceApplication, error) {
if !isValidUUID(id) {
return MarketplaceApplication{}, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiMarketplaceApplicationBase, id),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response MarketplaceApplication
err := r.execute(ctx, *c, &response)
return response, err
}
// CreateMarketplaceApplication creates a new marketplace application. Allowed
// values for Category are `nil`, `MarketplaceApplicationCMSCategory`,
// `MarketplaceApplicationProjectManagementCategory`,
// `MarketplaceApplicationAdminpanelCategory`,
// `MarketplaceApplicationCollaborationCategory`, `MarketplaceApplicationCloudStorageCategory`, `MarketplaceApplicationArchivingCategory`.
//
//See https://gridscale.io/en//api-documentation/index.html#operation/createMarketplaceApplication.
func (c *Client) CreateMarketplaceApplication(ctx context.Context, body MarketplaceApplicationCreateRequest) (MarketplaceApplicationCreateResponse, error) {
r := gsRequest{
uri: apiMarketplaceApplicationBase,
method: http.MethodPost,
body: body,
}
var response MarketplaceApplicationCreateResponse
err := r.execute(ctx, *c, &response)
return response, err
}
// ImportMarketplaceApplication imports a marketplace application. Allowed
// values for Category are `nil`, `MarketplaceApplicationCMSCategory`,
// `MarketplaceApplicationProjectManagementCategory`,
// `MarketplaceApplicationAdminpanelCategory`,
// `MarketplaceApplicationCollaborationCategory`,
// `MarketplaceApplicationCloudStorageCategory`,
// `MarketplaceApplicationArchivingCategory`.
//
// See https://gridscale.io/en//api-documentation/index.html#operation/createMarketplaceApplication.
func (c *Client) ImportMarketplaceApplication(ctx context.Context, body MarketplaceApplicationImportRequest) (MarketplaceApplicationCreateResponse, error) {
r := gsRequest{
uri: apiMarketplaceApplicationBase,
method: http.MethodPost,
body: body,
}
var response MarketplaceApplicationCreateResponse
err := r.execute(ctx, *c, &response)
return response, err
}
// UpdateMarketplaceApplication updates a marketplace application.
//
// See https://gridscale.io/en//api-documentation/index.html#operation/updateMarketplaceApplication.
func (c *Client) UpdateMarketplaceApplication(ctx context.Context, id string, body MarketplaceApplicationUpdateRequest) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiMarketplaceApplicationBase, id),
method: http.MethodPatch,
body: body,
}
return r.execute(ctx, *c, nil)
}
// DeleteMarketplaceApplication removes a marketplace application.
//
// See https://gridscale.io/en//api-documentation/index.html#operation/deleteMarketplaceApplication.
func (c *Client) DeleteMarketplaceApplication(ctx context.Context, id string) error {
if !isValidUUID(id) {
return errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiMarketplaceApplicationBase, id),
method: http.MethodDelete,
}
return r.execute(ctx, *c, nil)
}
// GetMarketplaceApplicationEventList gets list of a marketplace application's events.
//
// See https://gridscale.io/en//api-documentation/index.html#operation/getStorageEvents.
func (c *Client) GetMarketplaceApplicationEventList(ctx context.Context, id string) ([]Event, error) {
if !isValidUUID(id) {
return nil, errors.New("'id' is invalid")
}
r := gsRequest{
uri: path.Join(apiMarketplaceApplicationBase, id, "events"),
method: http.MethodGet,
skipCheckingRequest: true,
}
var response EventList
var marketAppEvents []Event
err := r.execute(ctx, *c, &response)
for _, properties := range response.List {
marketAppEvents = append(marketAppEvents, Event{Properties: properties})
}
return marketAppEvents, err
}