Skip to content

Commit c7663fc

Browse files
author
Mike Rostermund
authored
Merge pull request #179 from humio/mike/generate_client
Generate client using GraphQL schema
2 parents 3a98ee7 + de5e775 commit c7663fc

File tree

156 files changed

+47657
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+47657
-313
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: |
2525
export PATH=$PATH:$(go env GOPATH)/bin
2626
go install github.com/securego/gosec/v2/cmd/gosec@latest
27-
gosec ./...
27+
gosec -exclude-dir api -exclude-generated ./...
2828
- name: Run Staticcheck
2929
uses: dominikh/staticcheck-action@v1.3.1
3030
with:

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ GOFILES=$(wildcard *.go)
33
BIN_NAME=humioctl
44
BIN_PATH=bin/$(BIN_NAME)
55
CLI_COMMAND ?= ""
6+
SCHEMA_CLUSTER?=${HUMIO_ENDPOINT}
7+
SCHEMA_CLUSTER_API_TOKEN?=${HUMIO_TOKEN}
68

79
$(BIN_PATH): $(GOFILES)
810

@@ -24,6 +26,10 @@ snapshot:
2426
run: $(BIN_PATH)
2527
$(BIN_PATH) $(CLI_COMMAND)
2628

29+
update-schema:
30+
go run github.com/suessflorian/gqlfetch/gqlfetch@607d6757018016bba0ba7fd1cb9fed6aefa853b5 --endpoint ${SCHEMA_CLUSTER}/graphql --header "Authorization=Bearer ${SCHEMA_CLUSTER_API_TOKEN}" > internal/api/humiographql/schema/_schema.graphql
31+
printf "# Fetched from version %s" $$(curl --silent --location '${SCHEMA_CLUSTER}/api/v1/status' | jq -r ".version") >> internal/api/humiographql/schema/_schema.graphql
32+
2733
e2e: $(BIN_PATH)
2834
./e2e/run.bash
2935

api/actions.go

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,97 @@ package api
22

33
import (
44
"fmt"
5-
graphql "github.com/cli/shurcooL-graphql"
65
"reflect"
6+
7+
graphql "github.com/cli/shurcooL-graphql"
78
)
89

910
const (
10-
ActionTypeEmail string = "EmailAction"
11-
ActionTypeHumioRepo string = "HumioRepoAction"
12-
ActionTypeOpsGenie string = "OpsGenieAction"
13-
ActionTypePagerDuty string = "PagerDutyAction"
14-
ActionTypeSlack string = "SlackAction"
11+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
12+
ActionTypeEmail string = "EmailAction"
13+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
14+
ActionTypeHumioRepo string = "HumioRepoAction"
15+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
16+
ActionTypeOpsGenie string = "OpsGenieAction"
17+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
18+
ActionTypePagerDuty string = "PagerDutyAction"
19+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
20+
ActionTypeSlack string = "SlackAction"
21+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
1522
ActionTypeSlackPostMessage string = "SlackPostMessageAction"
16-
ActionTypeVictorOps string = "VictorOpsAction"
17-
ActionTypeWebhook string = "WebhookAction"
23+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
24+
ActionTypeVictorOps string = "VictorOpsAction"
25+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
26+
ActionTypeWebhook string = "WebhookAction"
1827
)
1928

29+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
2030
type Actions struct {
2131
client *Client
2232
}
2333

34+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
2435
type EmailAction struct {
2536
Recipients []string `graphql:"emailRecipients: recipients" yaml:"recipients,omitempty" json:"recipients,omitempty"`
2637
SubjectTemplate string `graphql:"emailSubjectTemplate: subjectTemplate" yaml:"subjectTemplate,omitempty" json:"subjectTemplate,omitempty"`
2738
BodyTemplate string `graphql:"emailBodyTemplate: bodyTemplate" yaml:"bodyTemplate,omitempty" json:"bodyTemplate,omitempty"`
2839
UseProxy bool `graphql:"emailUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
2940
}
3041

42+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3143
type HumioRepoAction struct {
3244
IngestToken string `graphql:"humioRepoIngestToken: ingestToken" yaml:"ingestToken,omitempty" json:"ingestToken,omitempty"`
3345
}
3446

47+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3548
type OpsGenieAction struct {
3649
ApiUrl string `graphql:"opsGenieApiUrl: apiUrl" yaml:"apiUrl,omitempty" json:"apiUrl,omitempty"`
3750
GenieKey string `graphql:"opsGenieGenieKey: genieKey" yaml:"genieKey,omitempty" json:"genieKey,omitempty"`
3851
UseProxy bool `graphql:"opsGenieUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
3952
}
4053

54+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
4155
type PagerDutyAction struct {
4256
Severity string `graphql:"pagerDutySeverity: severity" yaml:"severity,omitempty" json:"severity,omitempty"`
4357
RoutingKey string `graphql:"pagerDutyRoutingKey: routingKey" yaml:"routingKey,omitempty" json:"routingKey,omitempty"`
4458
UseProxy bool `graphql:"pagerDutyUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
4559
}
4660

61+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
4762
type SlackFieldEntryInput struct {
4863
FieldName string `graphql:"fieldName" yaml:"fieldName" json:"fieldName"`
4964
Value string `graphql:"value" yaml:"value" json:"value"`
5065
}
5166

67+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
5268
type SlackAction struct {
5369
Url string `graphql:"slackUrl: url" yaml:"url,omitempty" json:"url,omitempty"`
5470
Fields []SlackFieldEntryInput `graphql:"slackFields: fields" yaml:"fields,omitempty" json:"fields,omitempty"`
5571
UseProxy bool `graphql:"slackUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
5672
}
5773

74+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
5875
type SlackPostMessageAction struct {
5976
ApiToken string `graphql:"slackPostMessageApiToken: apiToken" yaml:"apiToken,omitempty" json:"apiToken,omitempty"`
6077
Channels []string `graphql:"slackPostMessageChannels: channels" yaml:"channels,omitempty" json:"channels,omitempty"`
6178
Fields []SlackFieldEntryInput `graphql:"slackPostMessageFields: fields" yaml:"fields,omitempty" json:"fields,omitempty"`
6279
UseProxy bool `graphql:"slackPostMessageUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
6380
}
6481

82+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
6583
type VictorOpsAction struct {
6684
MessageType string `graphql:"victorOpsMessageType: messageType" yaml:"messageType,omitempty" json:"messageType,omitempty"`
6785
NotifyUrl string `graphql:"victorOpsNotifyUrl: notifyUrl" yaml:"notifyUrl,omitempty" json:"notifyUrl,omitempty"`
6886
UseProxy bool `graphql:"victorOpsUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
6987
}
7088

89+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
7190
type HttpHeaderEntryInput struct {
7291
Header string `graphql:"header" yaml:"header" json:"header"`
7392
Value string `graphql:"value" yaml:"value" json:"value"`
7493
}
7594

95+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
7696
type WebhookAction struct {
7797
Method string `graphql:"webhookMethod: method" yaml:"method,omitempty" json:"method,omitempty"`
7898
Url string `graphql:"webhookUrl: url" yaml:"url,omitempty" json:"url,omitempty"`
@@ -82,6 +102,7 @@ type WebhookAction struct {
82102
UseProxy bool `graphql:"webhookUseProxy: useProxy" yaml:"useProxy,omitempty" json:"useProxy,omitempty"`
83103
}
84104

105+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
85106
type Action struct {
86107
Type string `graphql:"__typename" yaml:"type" json:"type"`
87108
ID string `graphql:"id" yaml:"-" json:"id"`
@@ -97,8 +118,10 @@ type Action struct {
97118
WebhookAction WebhookAction `graphql:"... on WebhookAction" yaml:"webhookAction,omitempty" json:"webhookAction,omitempty"`
98119
}
99120

121+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
100122
func (c *Client) Actions() *Actions { return &Actions{client: c} }
101123

124+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
102125
func (n *Actions) List(viewName string) ([]Action, error) {
103126
var query struct {
104127
SearchDomain struct {
@@ -114,6 +137,7 @@ func (n *Actions) List(viewName string) ([]Action, error) {
114137
return query.SearchDomain.Actions, err
115138
}
116139

140+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
117141
func (n *Actions) Update(viewName string, newAction *Action) (*Action, error) {
118142
if newAction == nil {
119143
return nil, fmt.Errorf("action must not be nil")
@@ -454,6 +478,7 @@ func (n *Actions) Update(viewName string, newAction *Action) (*Action, error) {
454478
return nil, fmt.Errorf("no action details specified or unsupported action type used")
455479
}
456480

481+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
457482
func (n *Actions) Add(viewName string, newAction *Action) (*Action, error) {
458483
if newAction == nil {
459484
return nil, fmt.Errorf("action must not be nil")
@@ -781,6 +806,7 @@ func (n *Actions) Add(viewName string, newAction *Action) (*Action, error) {
781806
return nil, fmt.Errorf("no action details specified or unsupported action type used")
782807
}
783808

809+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
784810
func (n *Actions) Get(viewName, actionName string) (*Action, error) {
785811
actions, err := n.List(viewName)
786812
if err != nil {
@@ -795,6 +821,7 @@ func (n *Actions) Get(viewName, actionName string) (*Action, error) {
795821
return nil, ActionNotFound(actionName)
796822
}
797823

824+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
798825
func (n *Actions) GetByID(viewName, actionID string) (*Action, error) {
799826
var query struct {
800827
SearchDomain struct {
@@ -819,6 +846,7 @@ func (n *Actions) GetByID(viewName, actionID string) (*Action, error) {
819846
return query.SearchDomain.Action, err
820847
}
821848

849+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
822850
func (n *Actions) Delete(viewName, actionName string) error {
823851
actions, err := n.List(viewName)
824852
if err != nil {

api/aggregate-alerts.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package api
22

33
import (
44
"fmt"
5+
56
graphql "github.com/cli/shurcooL-graphql"
67
"github.com/humio/cli/api/internal/humiographql"
78
)
89

10+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
911
type AggregateAlert struct {
1012
ID string `graphql:"id" yaml:"-" json:"id"`
1113
Name string `graphql:"name" yaml:"name" json:"name"`
@@ -23,12 +25,15 @@ type AggregateAlert struct {
2325
RunAsUserID string `graphql:"runAsUserId" yaml:"runAsUserId,omitempty" json:"runAsUserId,omitempty"`
2426
}
2527

28+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
2629
type AggregateAlerts struct {
2730
client *Client
2831
}
2932

33+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3034
func (c *Client) AggregateAlerts() *AggregateAlerts { return &AggregateAlerts{client: c} }
3135

36+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3237
func (a *AggregateAlerts) List(viewName string) ([]*AggregateAlert, error) {
3338
if viewName == "" {
3439
return nil, fmt.Errorf("viewName must not be empty")
@@ -58,6 +63,7 @@ func (a *AggregateAlerts) List(viewName string) ([]*AggregateAlert, error) {
5863
return aggregateAlerts, nil
5964
}
6065

66+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
6167
func (a *AggregateAlerts) Update(viewName string, updatedAggregateAlert *AggregateAlert) (*AggregateAlert, error) {
6268
if viewName == "" {
6369
return nil, fmt.Errorf("viewName must not be empty")
@@ -117,6 +123,7 @@ func (a *AggregateAlerts) Update(viewName string, updatedAggregateAlert *Aggrega
117123
return &aggregateAlert, nil
118124
}
119125

126+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
120127
func (a *AggregateAlerts) Create(viewName string, newAggregateAlert *AggregateAlert) (*AggregateAlert, error) {
121128
if viewName == "" {
122129
return nil, fmt.Errorf("viewName must not be empty")
@@ -171,6 +178,7 @@ func (a *AggregateAlerts) Create(viewName string, newAggregateAlert *AggregateAl
171178
return &aggregateAlert, nil
172179
}
173180

181+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
174182
func (a *AggregateAlerts) Delete(viewName, aggregateAlertID string) error {
175183
if viewName == "" {
176184
return fmt.Errorf("viewName must not be empty")
@@ -198,6 +206,7 @@ func (a *AggregateAlerts) Delete(viewName, aggregateAlertID string) error {
198206
return err
199207
}
200208

209+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
201210
func (a *AggregateAlerts) Get(viewName string, aggregateAlertID string) (*AggregateAlert, error) {
202211
var query struct {
203212
SearchDomain struct {

api/alerts.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package api
22

33
import (
44
"fmt"
5+
56
graphql "github.com/cli/shurcooL-graphql"
67
"github.com/humio/cli/api/internal/humiographql"
78
)
89

10+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
911
type Alert struct {
1012
ID string `graphql:"id" yaml:"-" json:"id"`
1113
Name string `graphql:"name" yaml:"name" json:"name"`
@@ -25,16 +27,21 @@ type Alert struct {
2527
}
2628

2729
const (
28-
QueryOwnershipTypeUser string = "User"
30+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
31+
QueryOwnershipTypeUser string = "User"
32+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
2933
QueryOwnershipTypeOrganization string = "Organization"
3034
)
3135

36+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3237
type Alerts struct {
3338
client *Client
3439
}
3540

41+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3642
func (c *Client) Alerts() *Alerts { return &Alerts{client: c} }
3743

44+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
3845
func (a *Alerts) List(viewName string) ([]Alert, error) {
3946
var query struct {
4047
SearchDomain struct {
@@ -55,6 +62,7 @@ func (a *Alerts) List(viewName string) ([]Alert, error) {
5562
return alerts, err
5663
}
5764

65+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
5866
func (a *Alerts) Update(viewName string, newAlert *Alert) (*Alert, error) {
5967
if newAlert == nil {
6068
return nil, fmt.Errorf("newAlert must not be nil")
@@ -108,6 +116,7 @@ func (a *Alerts) Update(viewName string, newAlert *Alert) (*Alert, error) {
108116
return &alert, nil
109117
}
110118

119+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
111120
func (a *Alerts) Add(viewName string, newAlert *Alert) (*Alert, error) {
112121
if newAlert == nil {
113122
return nil, fmt.Errorf("newAlert must not be nil")
@@ -155,6 +164,7 @@ func (a *Alerts) Add(viewName string, newAlert *Alert) (*Alert, error) {
155164
return &alert, nil
156165
}
157166

167+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
158168
func (a *Alerts) Get(viewName, alertName string) (*Alert, error) {
159169
alerts, err := a.List(viewName)
160170
if err != nil {
@@ -169,6 +179,7 @@ func (a *Alerts) Get(viewName, alertName string) (*Alert, error) {
169179
return nil, AlertNotFound(alertName)
170180
}
171181

182+
// Deprecated: Should no longer be used. https://github.com/CrowdStrike/logscale-go-api-client-example
172183
func (a *Alerts) Delete(viewName, alertName string) error {
173184
actions, err := a.List(viewName)
174185
if err != nil {

0 commit comments

Comments
 (0)