-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathexamples.go
44 lines (36 loc) · 1.53 KB
/
examples.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
package examples
import (
"flag"
"os"
"github.com/crowdstrike/gofalcon/pkg/falcon_util"
)
// CommonAuthFlags is a struct that holds common authentication flags used for most examples
type CommonAuthFlags struct {
ClientId string
ClientSecret string
MemberCID string
Cloud string
}
func (c *CommonAuthFlags) PromptForRequiredFlags() {
if c.ClientId == "" {
c.ClientId = falcon_util.PromptUser("Please provide your OAuth2 API Client ID")
}
if c.ClientSecret == "" {
c.ClientSecret = falcon_util.PromptUser("Please provide your OAuth2 API Client Secret")
}
}
// SetupAuthFlags parses command line flags and returns a CommonAuthFlags struct
func SetupAuthFlags() *CommonAuthFlags {
commonAuthFlags := CommonAuthFlags{}
flag.StringVar(&commonAuthFlags.ClientId, "client-id", os.Getenv("FALCON_CLIENT_ID"), "Client ID for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_ID env)")
flag.StringVar(&commonAuthFlags.ClientSecret, "client-secret", os.Getenv("FALCON_CLIENT_SECRET"), "Client Secret for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_SECRET)")
flag.StringVar(&commonAuthFlags.MemberCID, "member-cid", os.Getenv("FALCON_MEMBER_CID"), "Member CID for MSSP (for cases when OAuth2 authenticates multiple CIDs)")
flag.StringVar(&commonAuthFlags.Cloud, "cloud", os.Getenv("FALCON_CLOUD"), "Falcon cloud abbreviation (us-1, us-2, eu-1, us-gov-1)")
return &commonAuthFlags
}
// HandleError panics when err is not nil
func HandleError(err error) {
if err != nil {
panic(err)
}
}