-
Notifications
You must be signed in to change notification settings - Fork 3
/
applications.go
93 lines (78 loc) · 2.98 KB
/
applications.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
package solus
import (
"context"
)
// ApplicationsService handles all available methods with applications.
type ApplicationsService service
// Application represents an application.
type Application struct {
ID int `json:"id"`
Name string `json:"name"`
Icon Icon `json:"icon"`
URL string `json:"url"`
CloudInitVersion string `json:"cloud_init_version"`
UserData string `json:"user_data_template"`
LoginLink LoginLink `json:"login_link"`
JSONSchema string `json:"json_schema"`
IsDefault bool `json:"is_default"`
IsVisible bool `json:"is_visible"`
IsBuiltin bool `json:"is_buildin"`
AvailablePlans []ShortPlan `json:"available_plans"`
}
// ShortApplication represents only ID and name of application.
type ShortApplication struct {
ID int `json:"id"`
Name string `json:"name"`
}
// LoginLinkType a type of login link to the application.
type LoginLinkType string
const (
// LoginLinkTypeNone indicates application without login link.
LoginLinkTypeNone LoginLinkType = "none"
// LoginLinkTypeURL indicates application with URL pattern login link.
LoginLinkTypeURL LoginLinkType = "url"
// LoginLinkTypeJSCode indicates application with custom JS code auth code.
LoginLinkTypeJSCode LoginLinkType = "js_code"
// LoginLinkTypeInfo indicates application with custom information in popup.
LoginLinkTypeInfo LoginLinkType = "info"
)
// LoginLink represents an application login link.
type LoginLink struct {
Type LoginLinkType `json:"type"`
Content string `json:"content"`
}
// ApplicationCreateRequest represents available properties for creating a new
// application.
type ApplicationCreateRequest struct {
Name string `json:"name"`
URL string `json:"url"`
IconID int `json:"icon_id"`
CloudInitVersion string `json:"cloud_init_version"`
UserDataTemplate string `json:"user_data_template"`
JSONSchema string `json:"json_schema"`
IsVisible bool `json:"is_visible"`
LoginLink LoginLink `json:"login_link"`
AvailablePlans []int `json:"available_plans,omitempty"`
}
// ApplicationsResponse represents paginated list of applications.
// This cursor can be used for iterating over all available applications.
type ApplicationsResponse struct {
paginatedResponse
Data []Application `json:"data"`
}
// Create creates new application.
func (s *ApplicationsService) Create(ctx context.Context, data ApplicationCreateRequest) (Application, error) {
var resp struct {
Data Application `json:"data"`
}
return resp.Data, s.client.create(ctx, "applications", data, &resp)
}
// List lists all applications.
func (s *ApplicationsService) List(ctx context.Context) (ApplicationsResponse, error) {
resp := ApplicationsResponse{
paginatedResponse: paginatedResponse{
service: (*service)(s),
},
}
return resp, s.client.list(ctx, "applications", &resp)
}