-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapplication_api.go
More file actions
141 lines (120 loc) · 4.03 KB
/
application_api.go
File metadata and controls
141 lines (120 loc) · 4.03 KB
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
package api
import (
"github.com/SecurityDo/ingext_api/client"
"github.com/SecurityDo/ingext_api/model"
)
// PlatformService provides helpers for calling platform_* endpoints.
type ApplicationService struct {
client *client.IngextClient
}
// NewPlatformService constructs a PlatformService instance backed by the provided client.
func NewApplicationService(client *client.IngextClient) *ApplicationService {
return &ApplicationService{client: client}
}
func (s *ApplicationService) call(function string, payload interface{}, out interface{}) error {
return ApiCall(s.client, function, payload, out)
}
func (s *ApplicationService) ListAppTemplates() (*ListAppTemplateResponse, error) {
var resp ListAppTemplateResponse
if err := s.call("platform_list_application_template", nil, &resp); err != nil {
return nil, err
}
return &resp, nil
}
type ListAppTemplateResponse struct {
Entries []*model.ApplicationTemplateConfig `json:"entries"`
}
type ListAppInstanceResponse struct {
Entries []*model.InstanceState `json:"entries"`
}
func (s *ApplicationService) ListAppInstances() (*ListAppInstanceResponse, error) {
var resp ListAppInstanceResponse
if err := s.call("platform_list_application_template", nil, &resp); err != nil {
return nil, err
}
return &resp, nil
}
type InstallAppInstanceRequest struct {
Config *model.InstanceConfig `json:"config"`
}
func (s *ApplicationService) InstallAppTemplate(req *InstallAppInstanceRequest) error {
//var resp ListAppTemplateResponse
if err := s.call("platform_install_application_instance", req, nil); err != nil {
return err
}
return nil
}
type UnInstallAppInstanceRequest struct {
Application string `json:"application,omitempty" yaml:"application,omitempty"`
Instance string `json:"instance,omitempty" yaml:"instance,omitempty"`
}
func (s *ApplicationService) UnInstallAppTemplate(req *UnInstallAppInstanceRequest) error {
//var resp ListAppTemplateResponse
if err := s.call("platform_uninstall_application_instance", req, nil); err != nil {
return err
}
return nil
}
func (s *ApplicationService) AddAppTemplate(content string) (id string, err error) {
request := &GenericDAORequest[model.AppTemplateEntry]{
Action: "add",
Args: &GenericDAORequestArgs[model.AppTemplateEntry]{
//Id: args.Id,
Entry: &model.AppTemplateEntry{Content: content},
},
}
var resp GenericDaoAddResponse
if err := s.call("platform_application_template_dao", request, &resp); err != nil {
return "", err
}
return resp.ID, nil
}
func (s *ApplicationService) DeleteAppTemplate(name string) (err error) {
request := &GenericDAORequest[model.AppTemplateEntry]{
Action: "delete",
Args: &GenericDAORequestArgs[model.AppTemplateEntry]{
Id: name,
},
}
//var resp GenericDaoAddResponse
if err := s.call("platform_application_template_dao", request, nil); err != nil {
return err
}
return nil
}
func (s *ApplicationService) UpdateAppTemplate(name string, content string) (err error) {
request := &GenericDAORequest[model.AppTemplateEntry]{
Action: "update",
Args: &GenericDAORequestArgs[model.AppTemplateEntry]{
Id: name,
Entry: &model.AppTemplateEntry{
Content: content,
},
},
}
//var resp GenericDaoAddResponse
if err := s.call("platform_application_template_dao", request, nil); err != nil {
return err
}
return nil
}
type GetAppInstanceRequest struct {
Application string `json:"application,omitempty" yaml:"application,omitempty"`
Instance string `json:"instance,omitempty" yaml:"instance,omitempty"`
}
type GetAppInstanceResponse struct {
//State *applicationAPI.InstanceState `json:"state"`
//Actions []*applicationAPI.AppInstanceAction `json:"actions"`
Outputs []*model.InputParameter `json:"outputs,omitempty"`
}
func (s *ApplicationService) GetAppInstance(app string, instance string) (res *GetAppInstanceResponse, err error) {
request := &GetAppInstanceRequest{
Application: app,
Instance: instance,
}
var resp GetAppInstanceResponse
if err := s.call("platform_get_application_instance", request, &resp); err != nil {
return nil, err
}
return &resp, nil
}