-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgui_app_framework.go
1575 lines (1360 loc) · 51 KB
/
gui_app_framework.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package goqradar
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
)
//------------------------------------------------------------------------------
// Structures
//------------------------------------------------------------------------------
// StatusAppInstall is the status of the application installs.
type StatusAppInstall struct {
ApplicationID int `json:"application_id"`
Status string `json:"status"`
ErrorMessages string `json:"error_messages,omitempty"`
}
// StatusAppInstallsPaginatedResponse is the paginated response.
type StatusAppInstallsPaginatedResponse struct {
Total int `json:"total"`
Min int `json:"min"`
Max int `json:"max"`
StatusAppInstalls []*StatusAppInstall `json:"status_app_installs"`
}
// CreatedAppFramework is a QRadar Created application framework.
type CreatedAppFramework struct {
ApplicationID int `json:"application_id"`
ErrorMessages string `json:"error_messages"`
ErrorMessagesJSON []struct {
Code string `json:"code"`
Message string `json:"message"`
Source string `json:"source"`
} `json:"error_messages_json"`
Status string `json:"status"`
}
// AuthRequest is an authorisation request for an application install.
type AuthRequest struct {
Capabilities []string `json:"capabilities"`
}
// AuthRequestResponse is the response of an authorisation request for an application install.
type AuthRequestResponse struct {
Capabilities []string `json:"capabilities"`
UserID int `json:"user_id"`
}
// AppDefinition is a QRadar application definition
type AppDefinition struct {
ApplicationDefinitionID int `json:"application_definition_id"`
CreatedBy string `json:"created_by"`
CreatedOn int `json:"created_on"`
ErrorMessages string `json:"error_messages"`
ErrorMessagesJSON []struct {
Code string `json:"code"`
Message string `json:"message"`
Source string `json:"source"`
} `json:"error_messages_json"`
Manifest struct {
AppID int `json:"app_id"`
Areas []struct {
Description string `json:"description"`
ID string `json:"id"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
Text string `json:"text"`
URL string `json:"url"`
} `json:"areas"`
Authentication struct {
Oauth2 struct {
AuthorizationFlow string `json:"authorization_flow"`
RequestedCapabilities []string `json:"requested_capabilities"`
} `json:"oauth2"`
} `json:"authentication"`
ConfigurationPages []struct {
Description string `json:"description"`
Icon string `json:"icon"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
Text string `json:"text"`
URL string `json:"url"`
} `json:"configuration_pages"`
ConsoleIP string `json:"console_ip"`
CustomColumns []struct {
Label string `json:"label"`
NamedService string `json:"named_service"`
PageID string `json:"page_id"`
RequiredCapabilities []string `json:"required_capabilities"`
RestEndpoint string `json:"rest_endpoint"`
} `json:"custom_columns"`
DashboardItems []struct {
Description string `json:"description"`
RequiredCapabilities []string `json:"required_capabilities"`
RestMethod string `json:"rest_method"`
Text string `json:"text"`
} `json:"dashboard_items"`
Dependencies struct {
PipDirectory string `json:"pip_directory"`
RpmsDirectory string `json:"rpms_directory"`
} `json:"dependencies"`
Description string `json:"description"`
EnvironmentVariables []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"environment_variables"`
Fragments []struct {
AppName string `json:"app_name"`
Location string `json:"location"`
NamedService string `json:"named_service"`
PageID string `json:"page_id"`
RequiredCapabilities []string `json:"required_capabilities"`
RestEndpoint string `json:"rest_endpoint"`
} `json:"fragments"`
GuiActions []struct {
Description string `json:"description"`
Groups []string `json:"groups"`
Icon string `json:"icon"`
ID string `json:"id"`
Javascript string `json:"javascript"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
RestMethod string `json:"rest_method"`
Text string `json:"text"`
} `json:"gui_actions"`
LoadFlask string `json:"load_flask"`
LogLevel string `json:"log_level"`
MetadataProviders []struct {
MetadataType string `json:"metadata_type"`
RestMethod string `json:"rest_method"`
} `json:"metadata_providers"`
MultitenancySafe string `json:"multitenancy_safe"`
Name string `json:"name"`
PageScripts []struct {
AppName string `json:"app_name"`
NamedService string `json:"named_service"`
PageID string `json:"page_id"`
Scripts []string `json:"scripts"`
} `json:"page_scripts"`
ResourceBundles []struct {
Bundle string `json:"bundle"`
Locale string `json:"locale"`
} `json:"resource_bundles"`
Resources struct {
Memory int `json:"memory"`
} `json:"resources"`
RestMethods []struct {
ArgumentNames []string `json:"argument_names"`
Method string `json:"method"`
Name string `json:"name"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
URL string `json:"url"`
} `json:"rest_methods"`
Services []struct {
Autorestart string `json:"autorestart"`
Autostart string `json:"autostart"`
Command string `json:"command"`
Directory string `json:"directory"`
Endpoints []struct {
ErrorMimeType string `json:"error_mime_type"`
HTTPMethod string `json:"http_method"`
Name string `json:"name"`
Parameters []struct {
Definition string `json:"definition"`
Location string `json:"location"`
Name string `json:"name"`
} `json:"parameters"`
Path string `json:"path"`
RequestMimeType string `json:"request_mime_type"`
Response struct {
MimeType string `json:"mime_type"`
} `json:"response"`
} `json:"endpoints"`
Environment string `json:"environment"`
Exitcodes string `json:"exitcodes"`
Name string `json:"name"`
Numprocs int `json:"numprocs"`
Port int `json:"port"`
Priority int `json:"priority"`
ProcessName string `json:"process_name"`
RedirectStderr string `json:"redirect_stderr"`
Serverurl string `json:"serverurl"`
Startretries int `json:"startretries"`
Startsecs int `json:"startsecs"`
StderrCaptureMaxbytes string `json:"stderr_capture_maxbytes"`
StderrEventsEnabled string `json:"stderr_events_enabled"`
StderrLogfile string `json:"stderr_logfile"`
StderrLogfileBackups int `json:"stderr_logfile_backups"`
StderrLogfileMaxbytes string `json:"stderr_logfile_maxbytes"`
StdoutCaptureMaxbytes string `json:"stdout_capture_maxbytes"`
StdoutEventsEnabled string `json:"stdout_events_enabled"`
StdoutLogfile string `json:"stdout_logfile"`
StdoutLogfileBackups int `json:"stdout_logfile_backups"`
StdoutLogfileMaxbyte string `json:"stdout_logfile_maxbyte"`
Stopsignal string `json:"stopsignal"`
Stopwaitsecs int `json:"stopwaitsecs"`
Umask string `json:"umask"`
User string `json:"user"`
UUID string `json:"uuid"`
Version string `json:"version"`
} `json:"services"`
SingleInstanceOnly string `json:"single_instance_only"`
UUID string `json:"uuid"`
Version string `json:"version"`
} `json:"manifest"`
Status string `json:"status"`
UserRoleIds []int `json:"user_role_ids"`
}
// AppDefinitionsPaginatedResponse is the paginated response.
type AppDefinitionsPaginatedResponse struct {
Total int `json:"total"`
Min int `json:"min"`
Max int `json:"max"`
AppDefinitions []*AppDefinition `json:"status_app_installs"`
}
// AppDefinitionStatus is a QRadar application definition status.
type AppDefinitionStatus struct {
ApplicationDefinitionID int `json:"application_definition_id"`
ErrorMessages string `json:"error_messages"`
Status string `json:"status"`
}
// UserRoleID is a Qradar user role id
type UserRoleID struct {
UserRoles []int `json:"user_roles"`
}
// UserRoleIDsPaginatedResponse is the paginated response.
type UserRoleIDsPaginatedResponse struct {
Total int `json:"total"`
Min int `json:"min"`
Max int `json:"max"`
UserRoleIDs []*UserRoleID `json:"status_app_installs"`
}
// InstalledApp is a Qradar install application.
type InstalledApp struct {
ApplicationDefinitionID int `json:"application_definition_id"`
ApplicationState struct {
ApplicationID string `json:"application_id"`
ErrorMessages string `json:"error_messages"`
ErrorMessagesJSON []struct {
Code string `json:"code"`
Message string `json:"message"`
Source string `json:"source"`
} `json:"error_messages_json"`
Memory int `json:"memory"`
Status string `json:"status"`
} `json:"application_state"`
AuthClientUserID int `json:"auth_client_user_id"`
InstalledBy string `json:"installed_by"`
InstalledOn int `json:"installed_on"`
ManagedHostID int `json:"managed_host_id"`
Manifest struct {
AppID int `json:"app_id"`
Areas []struct {
Description string `json:"description"`
ID string `json:"id"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
Text string `json:"text"`
URL string `json:"url"`
} `json:"areas"`
Authentication struct {
Oauth2 struct {
AuthorizationFlow string `json:"authorization_flow"`
RequestedCapabilities []string `json:"requested_capabilities"`
} `json:"oauth2"`
} `json:"authentication"`
ConfigurationPages []struct {
Description string `json:"description"`
Icon string `json:"icon"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
Text string `json:"text"`
URL string `json:"url"`
} `json:"configuration_pages"`
ConsoleIP string `json:"console_ip"`
CustomColumns []struct {
Label string `json:"label"`
NamedService string `json:"named_service"`
PageID string `json:"page_id"`
RequiredCapabilities []string `json:"required_capabilities"`
RestEndpoint string `json:"rest_endpoint"`
} `json:"custom_columns"`
DashboardItems []struct {
Description string `json:"description"`
RequiredCapabilities []string `json:"required_capabilities"`
RestMethod string `json:"rest_method"`
Text string `json:"text"`
} `json:"dashboard_items"`
Dependencies struct {
PipDirectory string `json:"pip_directory"`
RpmsDirectory string `json:"rpms_directory"`
} `json:"dependencies"`
Description string `json:"description"`
EnvironmentVariables []struct {
Name string `json:"name"`
Value string `json:"value"`
} `json:"environment_variables"`
Fragments []struct {
AppName string `json:"app_name"`
Location string `json:"location"`
NamedService string `json:"named_service"`
PageID string `json:"page_id"`
RequiredCapabilities []string `json:"required_capabilities"`
RestEndpoint string `json:"rest_endpoint"`
} `json:"fragments"`
GuiActions []struct {
Description string `json:"description"`
Groups []string `json:"groups"`
Icon string `json:"icon"`
ID string `json:"id"`
Javascript string `json:"javascript"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
RestMethod string `json:"rest_method"`
Text string `json:"text"`
} `json:"gui_actions"`
LoadFlask string `json:"load_flask"`
LogLevel string `json:"log_level"`
MetadataProviders []struct {
MetadataType string `json:"metadata_type"`
RestMethod string `json:"rest_method"`
} `json:"metadata_providers"`
MultitenancySafe string `json:"multitenancy_safe"`
Name string `json:"name"`
PageScripts []struct {
AppName string `json:"app_name"`
NamedService string `json:"named_service"`
PageID string `json:"page_id"`
Scripts []string `json:"scripts"`
} `json:"page_scripts"`
ResourceBundles []struct {
Bundle string `json:"bundle"`
Locale string `json:"locale"`
} `json:"resource_bundles"`
Resources struct {
Memory int `json:"memory"`
} `json:"resources"`
RestMethods []struct {
ArgumentNames []string `json:"argument_names"`
Method string `json:"method"`
Name string `json:"name"`
NamedService string `json:"named_service"`
RequiredCapabilities []string `json:"required_capabilities"`
URL string `json:"url"`
} `json:"rest_methods"`
Services []struct {
Autorestart string `json:"autorestart"`
Autostart string `json:"autostart"`
Command string `json:"command"`
Directory string `json:"directory"`
Endpoints []struct {
ErrorMimeType string `json:"error_mime_type"`
HTTPMethod string `json:"http_method"`
Name string `json:"name"`
Parameters []struct {
Definition string `json:"definition"`
Location string `json:"location"`
Name string `json:"name"`
} `json:"parameters"`
Path string `json:"path"`
RequestMimeType string `json:"request_mime_type"`
Response struct {
MimeType string `json:"mime_type"`
} `json:"response"`
} `json:"endpoints"`
Environment string `json:"environment"`
Exitcodes string `json:"exitcodes"`
Name string `json:"name"`
Numprocs int `json:"numprocs"`
Port int `json:"port"`
Priority int `json:"priority"`
ProcessName string `json:"process_name"`
RedirectStderr string `json:"redirect_stderr"`
Serverurl string `json:"serverurl"`
Startretries int `json:"startretries"`
Startsecs int `json:"startsecs"`
StderrCaptureMaxbytes string `json:"stderr_capture_maxbytes"`
StderrEventsEnabled string `json:"stderr_events_enabled"`
StderrLogfile string `json:"stderr_logfile"`
StderrLogfileBackups int `json:"stderr_logfile_backups"`
StderrLogfileMaxbytes string `json:"stderr_logfile_maxbytes"`
StdoutCaptureMaxbytes string `json:"stdout_capture_maxbytes"`
StdoutEventsEnabled string `json:"stdout_events_enabled"`
StdoutLogfile string `json:"stdout_logfile"`
StdoutLogfileBackups int `json:"stdout_logfile_backups"`
StdoutLogfileMaxbyte string `json:"stdout_logfile_maxbyte"`
Stopsignal string `json:"stopsignal"`
Stopwaitsecs int `json:"stopwaitsecs"`
Umask string `json:"umask"`
User string `json:"user"`
UUID string `json:"uuid"`
Version string `json:"version"`
} `json:"services"`
SingleInstanceOnly string `json:"single_instance_only"`
UUID string `json:"uuid"`
Version string `json:"version"`
} `json:"manifest"`
SecurityProfileID int `json:"security_profile_id"`
}
// InstalledAppsPaginatedResponse is the paginated response.
type InstalledAppsPaginatedResponse struct {
Total int `json:"total"`
Min int `json:"min"`
Max int `json:"max"`
InstalledApps []*InstalledApp `json:"status_app_installs"`
}
// RegisteredService is a QRadar named service registered with the application framework.
type RegisteredService struct {
Name string `json:"name"`
Version string `json:"version"`
ApplicationID int `json:"application_id"`
UUID string `json:"uuid"`
Endpoints []struct {
Name string `json:"name"`
Path string `json:"path"`
HTTPMethod string `json:"http_method"`
Parameters []struct {
Location string `json:"location"`
Name string `json:"name"`
} `json:"parameters,omitempty"`
Response struct {
MimeType string `json:"mime_type"`
BodyType struct {
Type string `json:"@type"`
ResourceID string `json:"resource_id"`
ResourceName string `json:"resource_name"`
ResourceOwner string `json:"resource_owner"`
} `json:"body_type"`
} `json:"response"`
ErrorMimeType string `json:"error_mime_type"`
RequestMimeType string `json:"request_mime_type,omitempty"`
RequestBodyType struct {
Type string `json:"@type"`
ResourceName string `json:"resource_name"`
ResourceOwner string `json:"resource_owner"`
} `json:"request_body_type,omitempty"`
} `json:"endpoints"`
}
// RegisteredServicesPaginatedResponse is the paginated response.
type RegisteredServicesPaginatedResponse struct {
Total int `json:"total"`
Min int `json:"min"`
Max int `json:"max"`
RegisteredServices []*RegisteredService `json:"status_app_installs"`
}
//------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------
// ListStatusAppInstalls returns the app installs with given fields, filters.
func (endpoint *Endpoint) ListStatusAppInstalls(ctx context.Context, fields, filter string, min, max int) (*StatusAppInstallsPaginatedResponse, error) {
// Options
options := []Option{}
if fields != "" {
options = append(options, WithParam("fields", fields))
}
if filter != "" {
options = append(options, WithParam("filter", filter))
}
options = append(options, WithHeader("Range", fmt.Sprintf("items=%d-%d", min, max)))
// Do the request
resp, err := endpoint.client.do(ctx, http.MethodGet, "/gui_app_framework/application_creation_task", options...)
if err != nil {
return nil, fmt.Errorf("error while calling the endpoint: %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("error with the status code: %d", resp.StatusCode)
}
// Process the Content-Range
min, max, total, err := parseContentRange(resp.Header.Get("Content-Range"))
if err != nil {
return nil, fmt.Errorf("error while parsing the content-range [%s]: %s", resp.Header.Get("Content-Range"), err)
}
// Prepare the response
response := &StatusAppInstallsPaginatedResponse{
Total: total,
Min: min,
Max: max,
}
// Decode the response
err = json.NewDecoder(resp.Body).Decode(&response.StatusAppInstalls)
if err != nil {
return nil, fmt.Errorf("error while decoding the response: %s", err)
}
return response, nil
}
// CreateAppFramework creates a new application within the application framework. ZIP FILE UPLOAD
func (endpoint *Endpoint) CreateAppFramework(ctx context.Context, filename, fields string) (*CreatedAppFramework, error) {
// Prepare the URL
var reqURL *url.URL
reqURL, err := url.Parse(endpoint.client.BaseURL)
if err != nil {
return nil, fmt.Errorf("Error while parsing the URL : %s", err)
}
reqURL.Path += "/gui_app_framework/application_creation_task"
// handle zip file
file, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("Error while opening the file : %s", err)
}
defer file.Close()
buff := new(bytes.Buffer)
writer := multipart.NewWriter(buff)
part, err := writer.CreateFormFile(filename, filepath.Base(file.Name()))
io.Copy(part, file)
writer.Close()
// Create the request
req, err := http.NewRequest("POST", reqURL.String(), buff)
if err != nil {
return nil, fmt.Errorf("Error while creating the request : %s", err)
}
// Set HTTP headers
req.Header.Set("SEC", endpoint.client.Token)
req.Header.Set("Version", endpoint.client.Version)
req.Header.Set("Content-Type", "application/zip")
if fields != "" {
req.Header.Set("fields", fields)
}
// Do the request
resp, err := endpoint.client.client.Do(req)
if err != nil {
return nil, fmt.Errorf("Error while doing the request : %s", err)
}
// Read the response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("Error while reading the request : %s", err)
}
// Prepare the response
var response *CreatedAppFramework
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// GetCreatedAppFramework retrieves an app status by id.
func (endpoint *Endpoint) GetCreatedAppFramework(ctx context.Context, id int, fields string) (*CreatedAppFramework, error) {
// Options
options := []Option{}
if fields != "" {
options = append(options, WithParam("fields", fields))
}
// Do the request
resp, err := endpoint.client.do(ctx, http.MethodGet, "/gui_app_framework/application_creation_task/"+strconv.Itoa(id), options...)
if err != nil {
return nil, fmt.Errorf("error while calling the endpoint: %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("error with the status code: %d", resp.StatusCode)
}
// Read the respsonse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *CreatedAppFramework
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// CancelCreatedAppFramework by id
func (endpoint *Endpoint) CancelCreatedAppFramework(ctx context.Context, id int, fields string) (*CreatedAppFramework, error) {
status := "CANCELLED"
// Options
options := []Option{}
if fields != "" {
options = append(options, WithParam("fields", fields))
}
// Prepare the URL
var reqURL *url.URL
reqURL, err := url.Parse(endpoint.client.BaseURL)
if err != nil {
return nil, fmt.Errorf("Error while parsing the URL : %s", err)
}
reqURL.Path += "/gui_app_framework/application_creation_task/"
reqURL.Path += strconv.Itoa(id)
// Create the data
d, err := json.Marshal(status)
if err != nil {
return nil, fmt.Errorf("Error while marshalling the values : %s", err)
}
// Create the request
req, err := http.NewRequest("POST", reqURL.String(), bytes.NewBuffer(d))
if err != nil {
return nil, fmt.Errorf("Error while creating the request : %s", err)
}
// Add optional parameters
q := req.URL.Query()
q.Add("fields", fields)
req.URL.RawQuery = q.Encode()
// Set HTTP headers
req.Header.Set("SEC", endpoint.client.Token)
req.Header.Set("Version", endpoint.client.Version)
req.Header.Set("Content-Type", "application/json")
// Do the request
resp, err := endpoint.client.client.Do(req)
if err != nil {
return nil, fmt.Errorf("Error while doing the request : %s", err)
}
defer resp.Body.Close()
// Read the respsonse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *CreatedAppFramework
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// GetAuthRequest retrieves an authorisation request by id.
func (endpoint *Endpoint) GetAuthRequest(ctx context.Context, id int, fields string) (*AuthRequest, error) {
// Options
options := []Option{}
if fields != "" {
options = append(options, WithParam("fields", fields))
}
// Do the request
resp, err := endpoint.client.do(ctx, http.MethodGet, "/gui_app_framework/application_creation_task/"+strconv.Itoa(id)+"/auth", options...)
if err != nil {
return nil, fmt.Errorf("error while calling the endpoint: %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("error with the status code: %d", resp.StatusCode)
}
// Read the respsonse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *AuthRequest
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// UpdateAuthRequestResponse by id
func (endpoint *Endpoint) UpdateAuthRequestResponse(ctx context.Context, id int, data map[string]string, fields string) (*AuthRequestResponse, error) {
// Prepare the URL
var reqURL *url.URL
reqURL, err := url.Parse(endpoint.client.BaseURL)
if err != nil {
return nil, fmt.Errorf("Error while parsing the URL : %s", err)
}
reqURL.Path += "/gui_app_framework/application_creation_task/" + strconv.Itoa(id) + "/auth"
// Create the data
d, err := json.Marshal(data)
if err != nil {
return nil, fmt.Errorf("Error while marshalling the values : %s", err)
}
// Create the request
req, err := http.NewRequest("POST", reqURL.String(), bytes.NewBuffer(d))
if err != nil {
return nil, fmt.Errorf("Error while creating the request : %s", err)
}
// Set HTTP headers
req.Header.Set("SEC", endpoint.client.Token)
req.Header.Set("Version", endpoint.client.Version)
req.Header.Set("Content-Type", "application/json")
if fields != "" {
req.Header.Set("fields", fields)
}
// Do the request
resp, err := endpoint.client.client.Do(req)
if err != nil {
return nil, fmt.Errorf("Error while doing the request : %s", err)
}
defer resp.Body.Close()
// Read the respsonse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *AuthRequestResponse
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// ListAppDefinitions returns the application definitions with given fields, filters.
func (endpoint *Endpoint) ListAppDefinitions(ctx context.Context, fields, filter string, min, max int) (*AppDefinitionsPaginatedResponse, error) {
// Options
options := []Option{}
if fields != "" {
options = append(options, WithParam("fields", fields))
}
if filter != "" {
options = append(options, WithParam("filter", filter))
}
options = append(options, WithHeader("Range", fmt.Sprintf("items=%d-%d", min, max)))
// Do the request
resp, err := endpoint.client.do(ctx, http.MethodGet, "/gui_app_framework/application_definitions", options...)
if err != nil {
return nil, fmt.Errorf("error while calling the endpoint: %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("error with the status code: %d", resp.StatusCode)
}
// Process the Content-Range
min, max, total, err := parseContentRange(resp.Header.Get("Content-Range"))
if err != nil {
return nil, fmt.Errorf("error while parsing the content-range [%s]: %s", resp.Header.Get("Content-Range"), err)
}
// Prepare the response
response := &AppDefinitionsPaginatedResponse{
Total: total,
Min: min,
Max: max,
}
// Decode the response
err = json.NewDecoder(resp.Body).Decode(&response.AppDefinitions)
if err != nil {
return nil, fmt.Errorf("error while decoding the response: %s", err)
}
return response, nil
}
// CreateAppDefinition initialises the asynchronous installation of a new application within the application framework. ZIP FILE UPLOAD
func (endpoint *Endpoint) CreateAppDefinition(ctx context.Context, filename, fields string) (*AppDefinitionStatus, error) {
// Prepare the URL
var reqURL *url.URL
reqURL, err := url.Parse(endpoint.client.BaseURL)
if err != nil {
return nil, fmt.Errorf("Error while parsing the URL : %s", err)
}
reqURL.Path += "/gui_app_framework/application_definitions"
// handle zip file
file, err := os.Open(filename)
if err != nil {
return nil, fmt.Errorf("Error while opening the file : %s", err)
}
defer file.Close()
buff := new(bytes.Buffer)
writer := multipart.NewWriter(buff)
part, err := writer.CreateFormFile(filename, filepath.Base(file.Name()))
io.Copy(part, file)
writer.Close()
// Create the request
req, err := http.NewRequest("POST", reqURL.String(), buff)
if err != nil {
return nil, fmt.Errorf("Error while creating the request : %s", err)
}
// Set HTTP headers
req.Header.Set("SEC", endpoint.client.Token)
req.Header.Set("Version", endpoint.client.Version)
req.Header.Set("Content-Type", "application/zip")
if fields != "" {
req.Header.Set("fields", fields)
}
// Do the request
resp, err := endpoint.client.client.Do(req)
if err != nil {
return nil, fmt.Errorf("Error while doing the request : %s", err)
}
// Read the response
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *AppDefinitionStatus
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// GetAppDefinition retrieves an app definition by id.
func (endpoint *Endpoint) GetAppDefinition(ctx context.Context, id int, fields string) (*AppDefinition, error) {
// Options
options := []Option{}
if fields != "" {
options = append(options, WithParam("fields", fields))
}
// Do the request
resp, err := endpoint.client.do(ctx, http.MethodGet, "/gui_app_framework/application_definitions/"+strconv.Itoa(id), options...)
if err != nil {
return nil, fmt.Errorf("error while calling the endpoint: %s", err)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("error with the status code: %d", resp.StatusCode)
}
// Read the respsonse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *AppDefinition
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// CancelAppDefinition by id
func (endpoint *Endpoint) CancelAppDefinition(ctx context.Context, id int, fields string) (*AppDefinitionStatus, error) {
status := "CANCELLED"
// Prepare the URL
var reqURL *url.URL
reqURL, err := url.Parse(endpoint.client.BaseURL)
if err != nil {
return nil, fmt.Errorf("Error while parsing the URL : %s", err)
}
reqURL.Path += "/gui_app_framework/application_definitions/"
reqURL.Path += strconv.Itoa(id)
// Create the data
d, err := json.Marshal(status)
if err != nil {
return nil, fmt.Errorf("Error while marshalling the values : %s", err)
}
// Create the request
req, err := http.NewRequest("POST", reqURL.String(), bytes.NewBuffer(d))
if err != nil {
return nil, fmt.Errorf("Error while creating the request : %s", err)
}
// Add optional parameters
q := req.URL.Query()
q.Add("fields", fields)
req.URL.RawQuery = q.Encode()
// Set HTTP headers
req.Header.Set("SEC", endpoint.client.Token)
req.Header.Set("Version", endpoint.client.Version)
req.Header.Set("Content-Type", "application/json")
if fields != "" {
req.Header.Set("fields", fields)
}
// Do the request
resp, err := endpoint.client.client.Do(req)
if err != nil {
return nil, fmt.Errorf("Error while doing the request : %s", err)
}
defer resp.Body.Close()
// Read the respsonse
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("error while reading the request : %s", err)
}
// Prepare the response
var response *AppDefinitionStatus
// Unmarshal the response
err = json.Unmarshal([]byte(body), &response)
if err != nil {
return nil, fmt.Errorf("Error while unmarshalling the response : %s. HTTP response is : %s", err, string(body))
}
return response, nil
}
// DeleteAppDefinition by ID
func (endpoint *Endpoint) DeleteAppDefinition(ctx context.Context, id int) error {
// Prepare the URL
var reqURL *url.URL
reqURL, err := url.Parse(endpoint.client.BaseURL)
if err != nil {
return fmt.Errorf("Error while parsing the URL : %s", err)
}
reqURL.Path += "/gui_app_framework/application_definitions/"
reqURL.Path += strconv.Itoa(id)
// Create the request
req, err := http.NewRequest("DELETE", reqURL.String(), nil)
if err != nil {
return fmt.Errorf("Error while creating the request : %s", err)
}
// Set HTTP headers
req.Header.Set("SEC", endpoint.client.Token)
req.Header.Set("Version", endpoint.client.Version)
req.Header.Set("Content-Type", "application/json")
// Do the request
resp, err := endpoint.client.client.Do(req)
if err != nil {
return fmt.Errorf("Error while doing the request : %s", err)
}