-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
1248 lines (1086 loc) · 44.2 KB
/
client.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
// Code generated by gql_clientgen, please do not edit
package assets
import (
"github.com/secureworks/taegis-sdk-go/client"
"github.com/secureworks/taegis-sdk-go/graphql"
"context"
"net/http"
"time"
)
// Client provides an easy to use Go client to the Assets API
type Client struct {
client *client.Client
url string
}
// New returns a new Client, ready for use
func New(url string, opts ...client.Option) *Client {
client := client.NewClient(opts...)
return &Client{
client: client,
url: url,
}
}
func (c *Client) makeRequest(ctx context.Context, req *graphql.Request, res interface{}) error {
header := http.Header{}
return graphql.ExecuteQueryContext(ctx, &graphql.QueryConfig{
HClient: c.client,
Header: header,
Output: res,
Request: req,
ServerURL: c.url,
})
}
const allAssetFields = `
id
hostId
rn
tenantId
sensorTenant
sensorId
ingestTime
createdAt
updatedAt
deletedAt
biosSerial
firstDiskSerial
systemVolumeSerial
sensorVersion
endpointType
endpointPlatform
hostnames {` + allHostnameFields + `
}
ethernetAddresses {` + allEthernetAddressFields + `
}
ipAddresses {` + allIpAddressFields + `
}
users {` + allUserFields + `
}
architecture
osFamily
osVersion
osDistributor
osRelease
systemType
osCodename
kernelRelease
kernelVersion
tags {` + allTagFields + `
}
`
const allAssetCountsFields = `
count
`
const allAssetCountsByEndpointTypeFields = `
endpointType
count
`
const allAssetHistoryFields = `
id
createdAt
updatedAt
assetId
tenantId
hostId
action
who
reason
`
const allAssetHistoryContactFields = `
email
name
sub
`
const allAssetHistoryEventFields = `
domainName
hostName
`
const allAssetHistoryIdFields = `
hostId
instanceId
`
const allAssetRedCloakHistoryFields = `
action
allowedDomain
assetId
contact {` + allAssetHistoryContactFields + `
}
createdAt
event {` + allAssetHistoryEventFields + `
}
id {` + allAssetHistoryIdFields + `
}
reason
tenantId
`
const allAssetsExportOutputFields = `
columnDef
rows
totalCount
`
const allAssetsResultFields = `
totalResults
offset
limit
assets {` + allAssetFields + `
}
`
const allEndpointInfoFields = `
actualIsolationStatus
allowedDomain
color
desiredIsolationStatus
firstConnectTime
hostId
hostName
ignitionDetails {` + allIgnitionDetailsFields + `
}
lastConnectAddress
lastConnectServer
lastConnectTime
lastCrashCheck
lastModuleStatusTime
lastPredicateAuthtap
lastPredicateCyclorama
lastPredicateEntwine
lastPredicateGroundling
lastPredicateHostel
lastPredicateLacuna
lastPredicateMukluk
lastPredicatePeriodicscanControl
lastPredicatePeriodicscanResult
lastPredicateProcwall
lastPredicateSystemInformation
moduleHealth {` + allModuleHealthFields + `
}
moduleStatus {` + allModuleStatusFields + `
}
notableEventCount
sensorVersion
systemInformation {` + allSystemInformationFields + `
}
`
const allEthernetAddressFields = `
id
createdAt
updatedAt
hostId
mac
`
const allHostnameFields = `
id
createdAt
updatedAt
hostId
hostname
`
const allIgnitionDetailsFields = `
isEndpointConfigExist
requestStatus
`
const allIpAddressFields = `
id
createdAt
updatedAt
ip
hostId
`
const allModuleHealthFields = `
enabled
lastPredicateTime
lastRunningTime
moduleColor
moduleDisplayName
`
const allModuleStatusFields = `
enabled
moduleName
moduleState
`
const allSystemInformationFields = `
architecture
biosSerial
ethernetAddress
firstDiskSerial
hostName
ipAddress
isServerR2For2003And2008
productType
redcloakVersion
servicePack
systemVolumeSerial
windowsVersion
`
const allTagFields = `
id
hostId
tenantId
createdAt
updatedAt
tag
`
const allUpdateTagFields = `
id
tenantId
tag
`
const allUserFields = `
id
createdAt
updatedAt
hostId
username
`
// Type of Red Cloak endpoint agent.
type AgentType string
const (
AgentTypeEndpointRedcloak AgentType = "ENDPOINT_REDCLOAK"
AgentTypeEndpointCarbonBlack AgentType = "ENDPOINT_CARBON_BLACK"
AgentTypeEndpointCrowdStrike AgentType = "ENDPOINT_CROWD_STRIKE"
AgentTypeEndpointMicrosoftAtp AgentType = "ENDPOINT_MICROSOFT_ATP"
AgentTypeEndpointCarbonBlackPsc AgentType = "ENDPOINT_CARBON_BLACK_PSC"
)
// Describes an Asset in Red Cloak Taegis.
type Asset struct {
ID string `json:"id"`
HostId string `json:"hostId"`
Rn string `json:"rn"`
TenantId string `json:"tenantId"`
SensorTenant string `json:"sensorTenant"`
SensorId string `json:"sensorId"`
IngestTime time.Time `json:"ingestTime"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt"`
BiosSerial *string `json:"biosSerial"`
FirstDiskSerial *string `json:"firstDiskSerial"`
SystemVolumeSerial *string `json:"systemVolumeSerial"`
SensorVersion *string `json:"sensorVersion"`
EndpointType *string `json:"endpointType"`
EndpointPlatform *string `json:"endpointPlatform"`
Hostnames []Hostname `json:"hostnames"`
EthernetAddresses []EthernetAddress `json:"ethernetAddresses"`
IpAddresses []IpAddress `json:"ipAddresses"`
Users []User `json:"users"`
Architecture *string `json:"architecture"`
OsFamily *string `json:"osFamily"`
OsVersion *string `json:"osVersion"`
OsDistributor *string `json:"osDistributor"`
OsRelease *string `json:"osRelease"`
SystemType *string `json:"systemType"`
OsCodename *string `json:"osCodename"`
KernelRelease *string `json:"kernelRelease"`
KernelVersion *string `json:"kernelVersion"`
Tags []Tag `json:"tags"`
}
// Count of assets
type AssetCounts struct {
Count int `json:"count"`
}
type AssetCountsByEndpointType struct {
EndpointType string `json:"endpointType"`
Count int `json:"count"`
}
// Describes the history of an asset.
type AssetHistory struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
AssetId string `json:"assetId"`
TenantId string `json:"tenantId"`
HostId string `json:"hostId"`
Action string `json:"action"`
Who string `json:"who"`
Reason string `json:"reason"`
}
// Describes the contact of an asset history.
type AssetHistoryContact struct {
Email *string `json:"email"`
Name *string `json:"name"`
Sub *string `json:"sub"`
}
// Describes the event of an asset history.
type AssetHistoryEvent struct {
DomainName *string `json:"domainName"`
HostName *string `json:"hostName"`
}
// Contains the host id and instance id of an asset history.
type AssetHistoryId struct {
HostId *string `json:"hostId"`
InstanceId *string `json:"instanceId"`
}
// Describes the input of Asset data for creating an Asset Tag
type AssetInput struct {
ID string `json:"id"`
Tags []string `json:"tags"`
}
// Describes the Red Cloak agent history of an asset.
type AssetRedCloakHistory struct {
Action *string `json:"action"`
AllowedDomain []string `json:"allowedDomain"`
AssetId *string `json:"assetId"`
Contact *AssetHistoryContact `json:"contact"`
CreatedAt *string `json:"createdAt"`
Event *AssetHistoryEvent `json:"event"`
ID *AssetHistoryId `json:"id"`
Reason *string `json:"reason"`
TenantId *string `json:"tenantId"`
}
type AssetStateFilter string
const (
AssetStateFilterAll AssetStateFilter = "All"
AssetStateFilterDeleted AssetStateFilter = "Deleted"
AssetStateFilterActive AssetStateFilter = "Active"
AssetStateFilterUnhealthy AssetStateFilter = "Unhealthy"
)
type AssetsExportOutput struct {
ColumnDef []string `json:"columnDef"`
Rows []string `json:"rows"`
TotalCount *int `json:"totalCount"`
}
// Describes the enums available for the ordering of the <code>AllAssets</code> and <code>SearchAssets</code> queries.
type AssetsOrderByInput string
const (
AssetsOrderByInputHostname AssetsOrderByInput = "hostname"
AssetsOrderByInputIpAddress AssetsOrderByInput = "ip_address"
AssetsOrderByInputMacAddress AssetsOrderByInput = "mac_address"
AssetsOrderByInputTag AssetsOrderByInput = "tag"
AssetsOrderByInputUsername AssetsOrderByInput = "username"
AssetsOrderByInputOsVersion AssetsOrderByInput = "os_version"
AssetsOrderByInputEndpointType AssetsOrderByInput = "endpoint_type"
AssetsOrderByInputCreatedAt AssetsOrderByInput = "created_at"
AssetsOrderByInputUpdatedAt AssetsOrderByInput = "updated_at"
AssetsOrderByInputDeletedAt AssetsOrderByInput = "deleted_at"
AssetsOrderByInputOsFamily AssetsOrderByInput = "os_family"
AssetsOrderByInputOsDistributor AssetsOrderByInput = "os_distributor"
)
// Describes the order direction available for the order field of the <code>AllAssets</code> and <code>SearchAssets</code> queries.
type AssetsOrderDirectionInput string
const (
AssetsOrderDirectionInputAsc AssetsOrderDirectionInput = "asc"
AssetsOrderDirectionInputDesc AssetsOrderDirectionInput = "desc"
)
// Describes the return type of the <code>AllAssets</code> and <code>SearchAssets</code> queries.
type AssetsResult struct {
TotalResults int `json:"totalResults"`
Offset int `json:"offset"`
Limit int `json:"limit"`
Assets []Asset `json:"assets"`
}
// Describes the endpoint information of a Red Cloak agent asset.
type EndpointInfo struct {
ActualIsolationStatus *bool `json:"actualIsolationStatus"`
AllowedDomain []string `json:"allowedDomain"`
Color *string `json:"color"`
DesiredIsolationStatus *bool `json:"desiredIsolationStatus"`
FirstConnectTime *string `json:"firstConnectTime"`
HostId *string `json:"hostId"`
HostName *string `json:"hostName"`
IgnitionDetails *IgnitionDetails `json:"ignitionDetails"`
LastConnectAddress *string `json:"lastConnectAddress"`
LastConnectServer *string `json:"lastConnectServer"`
LastConnectTime *string `json:"lastConnectTime"`
LastCrashCheck *string `json:"lastCrashCheck"`
LastModuleStatusTime *string `json:"lastModuleStatusTime"`
LastPredicateAuthtap *string `json:"lastPredicateAuthtap"`
LastPredicateCyclorama *string `json:"lastPredicateCyclorama"`
LastPredicateEntwine *string `json:"lastPredicateEntwine"`
LastPredicateGroundling *string `json:"lastPredicateGroundling"`
LastPredicateHostel *string `json:"lastPredicateHostel"`
LastPredicateLacuna *string `json:"lastPredicateLacuna"`
LastPredicateMukluk *string `json:"lastPredicateMukluk"`
LastPredicatePeriodicscanControl *string `json:"lastPredicatePeriodicscanControl"`
LastPredicatePeriodicscanResult *string `json:"lastPredicatePeriodicscanResult"`
LastPredicateProcwall *string `json:"lastPredicateProcwall"`
LastPredicateSystemInformation *string `json:"lastPredicateSystemInformation"`
ModuleHealth []ModuleHealth `json:"moduleHealth"`
ModuleStatus []ModuleStatus `json:"moduleStatus"`
NotableEventCount *int `json:"notableEventCount"`
SensorVersion *int `json:"sensorVersion"`
SystemInformation *SystemInformation `json:"systemInformation"`
}
// Describes the ethernet address of an asset.
type EthernetAddress struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
HostId string `json:"hostId"`
Mac string `json:"mac"`
}
// Describes the hostname of an asset.
type Hostname struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
HostId string `json:"hostId"`
Hostname string `json:"hostname"`
}
// Describes the ignition details of a Red Cloak agent asset.
type IgnitionDetails struct {
IsEndpointConfigExist *bool `json:"isEndpointConfigExist"`
RequestStatus *string `json:"requestStatus"`
}
// Describes the IP Address of an asset.
type IpAddress struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Ip string `json:"ip"`
HostId string `json:"hostId"`
}
// Describes the ModuleHealth of a Red Cloak agent asset.
type ModuleHealth struct {
Enabled *string `json:"enabled"`
LastPredicateTime *string `json:"lastPredicateTime"`
LastRunningTime *string `json:"lastRunningTime"`
ModuleColor *string `json:"moduleColor"`
ModuleDisplayName *string `json:"moduleDisplayName"`
}
// Describes the module status of a Red Cloak agent asset.
type ModuleStatus struct {
Enabled *bool `json:"enabled"`
ModuleName *string `json:"moduleName"`
ModuleState *string `json:"moduleState"`
}
type SearchAssetsInput struct {
Hostname *string `json:"hostname"`
HostId *string `json:"host_id"`
IpAddress *string `json:"ip_address"`
MacAddress *string `json:"mac_address"`
OsVersion *string `json:"os_version"`
OsFamily *string `json:"os_family"`
OsDistributor *string `json:"os_distributor"`
Username *string `json:"username"`
EndpointType *string `json:"endpoint_type"`
Tag *string `json:"tag"`
HostIdPartialMatch *bool `json:"host_id_partial_match"`
OnlyMostRecent *bool `json:"only_most_recent"`
OrSearch *bool `json:"or_search"`
FilterAssetState *AssetStateFilter `json:"filter_asset_state"`
}
type SearchAssetsPaginationInput struct {
Offset *int `json:"offset"`
Limit *int `json:"limit"`
OrderBy *AssetsOrderByInput `json:"order_by"`
OrderDirection *AssetsOrderDirectionInput `json:"order_direction"`
}
// Describes the system information of a Red Cloak agent asset.
type SystemInformation struct {
Architecture *string `json:"architecture"`
BiosSerial *string `json:"biosSerial"`
EthernetAddress []string `json:"ethernetAddress"`
FirstDiskSerial *string `json:"firstDiskSerial"`
HostName *string `json:"hostName"`
IpAddress []string `json:"ipAddress"`
IsServerR2For2003And2008 *bool `json:"isServerR2For2003And2008"`
ProductType *string `json:"productType"`
RedcloakVersion *int `json:"redcloakVersion"`
ServicePack *string `json:"servicePack"`
SystemVolumeSerial *string `json:"systemVolumeSerial"`
WindowsVersion *string `json:"windowsVersion"`
}
// Describes the tag data associated with an asset
type Tag struct {
ID string `json:"id"`
HostId string `json:"hostId"`
TenantId string `json:"tenantId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Tag string `json:"tag"`
}
// Describes the tag data associated with an asset
type UpdateTag struct {
ID string `json:"id"`
TenantId string `json:"tenantId"`
Tag string `json:"tag"`
}
// Describes the user of an asset.
type User struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
HostId string `json:"hostId"`
Username string `json:"username"`
}
// GetTagCtx will gen an asset tag by id
func (c *Client) GetTagCtx(ctx context.Context, id string, opts ...graphql.RequestOption) (Tag, error) {
req := graphql.NewRequest(`query($id: ID!) {
tag(id: $id) {`+allTagFields+`
}
}`, opts...)
req.Var("id", id)
var res struct {
Tag Tag `json:"tag"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return Tag{}, err
}
return res.Tag, nil
}
// GetTag will gen an asset tag by id
func (c *Client) GetTag(id string, opts ...graphql.RequestOption) (Tag, error) {
return c.GetTagCtx(context.Background(), id, opts...)
}
// GetAssetCtx will get an asset by id
func (c *Client) GetAssetCtx(ctx context.Context, id string, opts ...graphql.RequestOption) (Asset, error) {
req := graphql.NewRequest(`query($id: ID!) {
asset(id: $id) {`+allAssetFields+`
}
}`, opts...)
req.Var("id", id)
var res struct {
Asset Asset `json:"asset"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return Asset{}, err
}
return res.Asset, nil
}
// GetAsset will get an asset by id
func (c *Client) GetAsset(id string, opts ...graphql.RequestOption) (Asset, error) {
return c.GetAssetCtx(context.Background(), id, opts...)
}
// GetAssetsByTagCtx will get a list of assets with tag
func (c *Client) GetAssetsByTagCtx(ctx context.Context, tags []string, opts ...graphql.RequestOption) ([]*Asset, error) {
req := graphql.NewRequest(`query($tags: [String!]!) {
assetsByTag(tags: $tags) {`+allAssetFields+`
}
}`, opts...)
req.Var("tags", tags)
var res struct {
AssetsByTag []*Asset `json:"assetsByTag"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AssetsByTag, nil
}
// GetAssetsByTag will get a list of assets with tag
func (c *Client) GetAssetsByTag(tags []string, opts ...graphql.RequestOption) ([]*Asset, error) {
return c.GetAssetsByTagCtx(context.Background(), tags, opts...)
}
// GetAllUniqueTagsCtx will get a list of all unique tags
func (c *Client) GetAllUniqueTagsCtx(ctx context.Context, opts ...graphql.RequestOption) ([]string, error) {
req := graphql.NewRequest(`query {
allUniqueTags
}`, opts...)
var res struct {
AllUniqueTags []string `json:"allUniqueTags"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AllUniqueTags, nil
}
// GetAllUniqueTags will get a list of all unique tags
func (c *Client) GetAllUniqueTags(opts ...graphql.RequestOption) ([]string, error) {
return c.GetAllUniqueTagsCtx(context.Background(), opts...)
}
// GetAssetEndpointInfoCtx will get RedCloak endpoint info by id
func (c *Client) GetAssetEndpointInfoCtx(ctx context.Context, id string, opts ...graphql.RequestOption) (EndpointInfo, error) {
req := graphql.NewRequest(`query($id: ID!) {
assetEndpointInfo(id: $id) {`+allEndpointInfoFields+`
}
}`, opts...)
req.Var("id", id)
var res struct {
AssetEndpointInfo EndpointInfo `json:"assetEndpointInfo"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return EndpointInfo{}, err
}
return res.AssetEndpointInfo, nil
}
// GetAssetEndpointInfo will get RedCloak endpoint info by id
func (c *Client) GetAssetEndpointInfo(id string, opts ...graphql.RequestOption) (EndpointInfo, error) {
return c.GetAssetEndpointInfoCtx(context.Background(), id, opts...)
}
// GetAllAssetsArguments is the parameters for GetAllAssets
type GetAllAssetsArguments struct {
Offset *int `json:"offset"`
Limit *int `json:"limit"`
OrderBy *AssetsOrderByInput `json:"order_by"`
OrderDirection *AssetsOrderDirectionInput `json:"order_direction"`
FilterAssetState *AssetStateFilter `json:"filter_asset_state"`
}
// GetAllAssetsCtx will get a list of assets
func (c *Client) GetAllAssetsCtx(ctx context.Context, params *GetAllAssetsArguments, opts ...graphql.RequestOption) (*AssetsResult, error) {
req := graphql.NewRequest(`query($offset: Int, $limit: Int, $order_by: AssetsOrderByInput, $order_direction: AssetsOrderDirectionInput, $filter_asset_state: AssetStateFilter) {
allAssets(offset: $offset, limit: $limit, order_by: $order_by, order_direction: $order_direction, filter_asset_state: $filter_asset_state) {`+allAssetsResultFields+`
}
}`, opts...)
req.Var("offset", params.Offset)
req.Var("limit", params.Limit)
req.Var("order_by", params.OrderBy)
req.Var("order_direction", params.OrderDirection)
req.Var("filter_asset_state", params.FilterAssetState)
var res struct {
AllAssets *AssetsResult `json:"allAssets"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AllAssets, nil
}
// GetAllAssets will get a list of assets
func (c *Client) GetAllAssets(params *GetAllAssetsArguments, opts ...graphql.RequestOption) (*AssetsResult, error) {
return c.GetAllAssetsCtx(context.Background(), params, opts...)
}
// GetAllAssetsExportCtx will get a list of assets for export to CSV
func (c *Client) GetAllAssetsExportCtx(ctx context.Context, offset *int, limit *int, opts ...graphql.RequestOption) (*AssetsResult, error) {
req := graphql.NewRequest(`query($offset: Int, $limit: Int) {
allAssetsExport(offset: $offset, limit: $limit) {`+allAssetsResultFields+`
}
}`, opts...)
req.Var("offset", offset)
req.Var("limit", limit)
var res struct {
AllAssetsExport *AssetsResult `json:"allAssetsExport"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AllAssetsExport, nil
}
// GetAllAssetsExport will get a list of assets for export to CSV
func (c *Client) GetAllAssetsExport(offset *int, limit *int, opts ...graphql.RequestOption) (*AssetsResult, error) {
return c.GetAllAssetsExportCtx(context.Background(), offset, limit, opts...)
}
// GetAssetCountCtx will count of assets of a specific endpoint_type
func (c *Client) GetAssetCountCtx(ctx context.Context, endpoint_type *AgentType, opts ...graphql.RequestOption) (AssetCounts, error) {
req := graphql.NewRequest(`query($endpoint_type: AgentType) {
assetCount(endpoint_type: $endpoint_type) {`+allAssetCountsFields+`
}
}`, opts...)
req.Var("endpoint_type", endpoint_type)
var res struct {
AssetCount AssetCounts `json:"assetCount"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return AssetCounts{}, err
}
return res.AssetCount, nil
}
// GetAssetCount will count of assets of a specific endpoint_type
func (c *Client) GetAssetCount(endpoint_type *AgentType, opts ...graphql.RequestOption) (AssetCounts, error) {
return c.GetAssetCountCtx(context.Background(), endpoint_type, opts...)
}
// GetAssetCountGroupByEndpointTypeCtx will count of assets of grouped by endpoint_type
func (c *Client) GetAssetCountGroupByEndpointTypeCtx(ctx context.Context, opts ...graphql.RequestOption) ([]*AssetCountsByEndpointType, error) {
req := graphql.NewRequest(`query {
assetCountGroupByEndpointType {`+allAssetCountsByEndpointTypeFields+`
}
}`, opts...)
var res struct {
AssetCountGroupByEndpointType []*AssetCountsByEndpointType `json:"assetCountGroupByEndpointType"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AssetCountGroupByEndpointType, nil
}
// GetAssetCountGroupByEndpointType will count of assets of grouped by endpoint_type
func (c *Client) GetAssetCountGroupByEndpointType(opts ...graphql.RequestOption) ([]*AssetCountsByEndpointType, error) {
return c.GetAssetCountGroupByEndpointTypeCtx(context.Background(), opts...)
}
// GetAllAssetsCountCtx will count of all assets
func (c *Client) GetAllAssetsCountCtx(ctx context.Context, opts ...graphql.RequestOption) (AssetCounts, error) {
req := graphql.NewRequest(`query {
allAssetsCount {`+allAssetCountsFields+`
}
}`, opts...)
var res struct {
AllAssetsCount AssetCounts `json:"allAssetsCount"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return AssetCounts{}, err
}
return res.AllAssetsCount, nil
}
// GetAllAssetsCount will count of all assets
func (c *Client) GetAllAssetsCount(opts ...graphql.RequestOption) (AssetCounts, error) {
return c.GetAllAssetsCountCtx(context.Background(), opts...)
}
// GetAssetsByIdsCtx will bulk lookup by ids
func (c *Client) GetAssetsByIdsCtx(ctx context.Context, ids []string, opts ...graphql.RequestOption) ([]*Asset, error) {
req := graphql.NewRequest(`query($ids: [ID!]) {
assetsByIds(ids: $ids) {`+allAssetFields+`
}
}`, opts...)
req.Var("ids", ids)
var res struct {
AssetsByIds []*Asset `json:"assetsByIds"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AssetsByIds, nil
}
// GetAssetsByIds will bulk lookup by ids
func (c *Client) GetAssetsByIds(ids []string, opts ...graphql.RequestOption) ([]*Asset, error) {
return c.GetAssetsByIdsCtx(context.Background(), ids, opts...)
}
// GetAssetsByHostIdsCtx will bulk lookup by hostIds
func (c *Client) GetAssetsByHostIdsCtx(ctx context.Context, hostIds []string, opts ...graphql.RequestOption) ([]*Asset, error) {
req := graphql.NewRequest(`query($hostIds: [String!]) {
assetsByHostIds(hostIds: $hostIds) {`+allAssetFields+`
}
}`, opts...)
req.Var("hostIds", hostIds)
var res struct {
AssetsByHostIds []*Asset `json:"assetsByHostIds"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AssetsByHostIds, nil
}
// GetAssetsByHostIds will bulk lookup by hostIds
func (c *Client) GetAssetsByHostIds(hostIds []string, opts ...graphql.RequestOption) ([]*Asset, error) {
return c.GetAssetsByHostIdsCtx(context.Background(), hostIds, opts...)
}
// GetAssetsByIpAddressesCtx will bulk lookup by ipAddress
func (c *Client) GetAssetsByIpAddressesCtx(ctx context.Context, ipAddresses []string, opts ...graphql.RequestOption) ([]*Asset, error) {
req := graphql.NewRequest(`query($ipAddresses: [String!]) {
assetsByIpAddresses(ipAddresses: $ipAddresses) {`+allAssetFields+`
}
}`, opts...)
req.Var("ipAddresses", ipAddresses)
var res struct {
AssetsByIpAddresses []*Asset `json:"assetsByIpAddresses"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AssetsByIpAddresses, nil
}
// GetAssetsByIpAddresses will bulk lookup by ipAddress
func (c *Client) GetAssetsByIpAddresses(ipAddresses []string, opts ...graphql.RequestOption) ([]*Asset, error) {
return c.GetAssetsByIpAddressesCtx(context.Background(), ipAddresses, opts...)
}
// GetAllAssetHistoriesCtx will get a list of asset histories for the tenant
func (c *Client) GetAllAssetHistoriesCtx(ctx context.Context, offset *int, limit *int, opts ...graphql.RequestOption) ([]*AssetHistory, error) {
req := graphql.NewRequest(`query($offset: Int, $limit: Int) {
allAssetHistories(offset: $offset, limit: $limit) {`+allAssetHistoryFields+`
}
}`, opts...)
req.Var("offset", offset)
req.Var("limit", limit)
var res struct {
AllAssetHistories []*AssetHistory `json:"allAssetHistories"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AllAssetHistories, nil
}
// GetAllAssetHistories will get a list of asset histories for the tenant
func (c *Client) GetAllAssetHistories(offset *int, limit *int, opts ...graphql.RequestOption) ([]*AssetHistory, error) {
return c.GetAllAssetHistoriesCtx(context.Background(), offset, limit, opts...)
}
// GetAssetRedCloakHistoriesCtx will get history of actions on an asset by id (includes RedCloack history)
func (c *Client) GetAssetRedCloakHistoriesCtx(ctx context.Context, id string, offset *int, limit *int, opts ...graphql.RequestOption) ([]*AssetRedCloakHistory, error) {
req := graphql.NewRequest(`query($id: ID!, $offset: Int, $limit: Int) {
assetRedCloakHistories(id: $id, offset: $offset, limit: $limit) {`+allAssetRedCloakHistoryFields+`
}
}`, opts...)
req.Var("id", id)
req.Var("offset", offset)
req.Var("limit", limit)
var res struct {
AssetRedCloakHistories []*AssetRedCloakHistory `json:"assetRedCloakHistories"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.AssetRedCloakHistories, nil
}
// GetAssetRedCloakHistories will get history of actions on an asset by id (includes RedCloack history)
func (c *Client) GetAssetRedCloakHistories(id string, offset *int, limit *int, opts ...graphql.RequestOption) ([]*AssetRedCloakHistory, error) {
return c.GetAssetRedCloakHistoriesCtx(context.Background(), id, offset, limit, opts...)
}
// GetSearchAssetsArguments is the parameters for GetSearchAssets
type GetSearchAssetsArguments struct {
Offset *int `json:"offset"`
Limit *int `json:"limit"`
Hostname *string `json:"hostname"`
HostId *string `json:"host_id"`
IpAddress *string `json:"ip_address"`
MacAddress *string `json:"mac_address"`
OsVersion *string `json:"os_version"`
OsFamily *string `json:"os_family"`
OsDistributor *string `json:"os_distributor"`
Username *string `json:"username"`
EndpointType *string `json:"endpoint_type"`
Tag *string `json:"tag"`
HostIdPartialMatch *bool `json:"host_id_partial_match"`
OnlyMostRecent *bool `json:"only_most_recent"`
OrderBy *AssetsOrderByInput `json:"order_by"`
OrderDirection *AssetsOrderDirectionInput `json:"order_direction"`
OrSearch *bool `json:"or_search"`
FilterAssetState *AssetStateFilter `json:"filter_asset_state"`
}
// GetSearchAssetsCtx will search assets. Soon to be deprecated
func (c *Client) GetSearchAssetsCtx(ctx context.Context, params *GetSearchAssetsArguments, opts ...graphql.RequestOption) (*AssetsResult, error) {
req := graphql.NewRequest(`query($offset: Int, $limit: Int, $hostname: String, $host_id: String, $ip_address: String, $mac_address: String, $os_version: String, $os_family: String, $os_distributor: String, $username: String, $endpoint_type: String, $tag: String, $host_id_partial_match: Boolean, $only_most_recent: Boolean, $order_by: AssetsOrderByInput, $order_direction: AssetsOrderDirectionInput, $or_search: Boolean, $filter_asset_state: AssetStateFilter) {
searchAssets(offset: $offset, limit: $limit, hostname: $hostname, host_id: $host_id, ip_address: $ip_address, mac_address: $mac_address, os_version: $os_version, os_family: $os_family, os_distributor: $os_distributor, username: $username, endpoint_type: $endpoint_type, tag: $tag, host_id_partial_match: $host_id_partial_match, only_most_recent: $only_most_recent, order_by: $order_by, order_direction: $order_direction, or_search: $or_search, filter_asset_state: $filter_asset_state) {`+allAssetsResultFields+`
}
}`, opts...)
req.Var("offset", params.Offset)
req.Var("limit", params.Limit)
req.Var("hostname", params.Hostname)
req.Var("host_id", params.HostId)
req.Var("ip_address", params.IpAddress)
req.Var("mac_address", params.MacAddress)
req.Var("os_version", params.OsVersion)
req.Var("os_family", params.OsFamily)
req.Var("os_distributor", params.OsDistributor)
req.Var("username", params.Username)
req.Var("endpoint_type", params.EndpointType)
req.Var("tag", params.Tag)
req.Var("host_id_partial_match", params.HostIdPartialMatch)
req.Var("only_most_recent", params.OnlyMostRecent)
req.Var("order_by", params.OrderBy)
req.Var("order_direction", params.OrderDirection)
req.Var("or_search", params.OrSearch)
req.Var("filter_asset_state", params.FilterAssetState)
var res struct {
SearchAssets *AssetsResult `json:"searchAssets"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.SearchAssets, nil
}
// GetSearchAssets will search assets. Soon to be deprecated
func (c *Client) GetSearchAssets(params *GetSearchAssetsArguments, opts ...graphql.RequestOption) (*AssetsResult, error) {
return c.GetSearchAssetsCtx(context.Background(), params, opts...)
}
// GetSearchAssetsV2Ctx will search assets v2
func (c *Client) GetSearchAssetsV2Ctx(ctx context.Context, input SearchAssetsInput, paginationInput *SearchAssetsPaginationInput, opts ...graphql.RequestOption) (*AssetsResult, error) {
req := graphql.NewRequest(`query($input: SearchAssetsInput!, $paginationInput: SearchAssetsPaginationInput) {
searchAssetsV2(input: $input, paginationInput: $paginationInput) {`+allAssetsResultFields+`
}
}`, opts...)
req.Var("input", input)
req.Var("paginationInput", paginationInput)
var res struct {
SearchAssetsV2 *AssetsResult `json:"searchAssetsV2"`
}
if err := c.makeRequest(ctx, req, &res); err != nil {
return nil, err
}
return res.SearchAssetsV2, nil
}