forked from CrowdStrike/gofalcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (51 loc) · 1.98 KB
/
main.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
package main
import (
"context"
"fmt"
"os"
"github.com/crowdstrike/gofalcon/falcon"
"github.com/crowdstrike/gofalcon/falcon/client/falcon_container"
"github.com/crowdstrike/gofalcon/pkg/falcon_util"
)
func main() {
falconClientId := os.Getenv("FALCON_CLIENT_ID")
falconClientSecret := os.Getenv("FALCON_CLIENT_SECRET")
clientCloud := os.Getenv("FALCON_CLOUD")
if falconClientId == "" {
falconClientId = falcon_util.PromptUser(`Missing FALCON_CLIENT_ID environment variable. Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
Falcon Client ID`)
}
if falconClientSecret == "" {
falconClientSecret = falcon_util.PromptUser(`Missing FALCON_CLIENT_SECRET environment variable. Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
Falcon Client Secret`)
}
client, err := falcon.NewClient(&falcon.ApiConfig{
ClientId: falconClientId,
ClientSecret: falconClientSecret,
Cloud: falcon.Cloud(clientCloud),
Context: context.Background(),
})
if err != nil {
panic(err)
}
res, err := client.FalconContainer.GetCredentials(&falcon_container.GetCredentialsParams{
Context: context.Background(),
})
if err != nil {
panic(err)
}
payload := res.GetPayload()
if err = falcon.AssertNoError(payload.Errors); err != nil {
traceId := ""
if payload.Meta != nil && payload.Meta.TraceID != nil {
traceId = *payload.Meta.TraceID
}
fmt.Fprintf(os.Stderr, "WARNING: %v (trace_id=%s)", err, traceId)
}
resources := payload.Resources
if len(resources) != 1 {
fmt.Fprintf(os.Stderr, "Expected to receive exactly one token, but got %d\n", len(resources))
panic("Unexpected response")
}
fmt.Printf("%s\n", *resources[0].Token)
}