-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: multiple issues with gofalcon example and client opts #38
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,28 +97,28 @@ func (c config) OK() error { | |
|
||
1. `config`: A type the raw json config is unmarshalled into. | ||
2. `logger`: A dedicated logger is provided to capture function logs in all environments (both locally and distributed). | ||
1. Using a different logger may produce logs in the runtime but won't make it into the logscale infrastructure. | ||
1. Using a different logger may produce logs in the runtime but won't make it into the logscale infrastructure. | ||
3. `Request`: Request payload and metadata. At the time of this writing, the `Request` struct consists of: | ||
1. `Body`: The input io.Reader for the payload as given in the Function Gateway `body` payload field or streamed | ||
in. | ||
2. `Params`: Contains request headers and query parameters. | ||
3. `URL`: The request path relative to the function as a string. | ||
4. `Method`: The request HTTP method or verb. | ||
5. `Context`: Caller-supplied raw context. | ||
6. `AccessToken`: Caller-supplied access token. | ||
1. `Body`: The input io.Reader for the payload as given in the Function Gateway `body` payload field or streamed | ||
in. | ||
2. `Params`: Contains request headers and query parameters. | ||
3. `URL`: The request path relative to the function as a string. | ||
4. `Method`: The request HTTP method or verb. | ||
5. `Context`: Caller-supplied raw context. | ||
6. `AccessToken`: Caller-supplied access token. | ||
4. `RequestOf`: The same as Request only that the Body field is json unmarshalled into the generic type (i.e. `request` | ||
type above) | ||
5. `Response` | ||
1. The `Response` contains fields `Body` (the payload of the response), `Code` (an HTTP status code), | ||
`Errors` (a slice of `APIError`s), and `Headers` (a map of any special HTTP headers which should be present on | ||
the response). | ||
1. The `Response` contains fields `Body` (the payload of the response), `Code` (an HTTP status code), | ||
`Errors` (a slice of `APIError`s), and `Headers` (a map of any special HTTP headers which should be present on | ||
the response). | ||
6. `main()`: Initialization and bootstrap logic all contained with fdk.Run and handler constructor. | ||
|
||
more examples can be found at: | ||
|
||
* [fn with config](examples/fn_config) | ||
* [fn without config](examples/fn_no_config) | ||
* [more complex/complete example](examples/complex) | ||
- [fn with config](examples/fn_config) | ||
- [fn without config](examples/fn_no_config) | ||
- [more complex/complete example](examples/complex) | ||
|
||
### Testing locally | ||
|
||
|
@@ -161,23 +161,19 @@ import ( | |
"log/slog" | ||
|
||
fdk "github.com/CrowdStrike/foundry-fn-go" | ||
"github.com/CrowdStrike/gofalcon/falcon" | ||
"github.com/CrowdStrike/gofalcon/falcon/client" | ||
"github.com/crowdstrike/gofalcon/falcon" | ||
"github.com/crowdstrike/gofalcon/falcon/client" | ||
) | ||
|
||
func newHandler(_ context.Context, _ *slog.Logger, cfg config) fdk.Handler { | ||
mux := fdk.NewMux() | ||
mux.Post("/echo", fdk.HandlerFn(func(ctx context.Context, r fdk.Request) fdk.Response { | ||
client, err := newFalconClient(ctx, r.AccessToken) | ||
if err != nil { | ||
if err == falcon.ErrFalconNoToken { | ||
// not a processable request | ||
return fdk.Response{ /* snip */ } | ||
} | ||
// some other error - see gofalcon documentation | ||
return fdk.Response{ Code: 500, Body: fdk.JSON(err) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the motivation for returning a jsonified err? I think we're better off sticking with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack hadn't seen this, will update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unfortunately, looking at the sample apps for foundry, we don't have funcitons that utilize even a small percentage of our best practices. They need some TLC, so things like |
||
} | ||
|
||
// trim rest | ||
// we have a valid gofalcon client | ||
})) | ||
return mux | ||
} | ||
|
@@ -188,7 +184,7 @@ func newFalconClient(ctx context.Context, token string) (*client.CrowdStrikeAPIS | |
AccessToken: token, | ||
Cloud: falcon.Cloud(opts.Cloud), | ||
Context: ctx, | ||
UserAgentOverride: out.UserAgent, | ||
UserAgentOverride: opts.UserAgent, | ||
}) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,14 @@ var version = "development" | |
// AccessToken: token, | ||
// Cloud: falcon.Cloud(opts.Cloud), | ||
// Context: ctx, | ||
// UserAgentOverride: out.UserAgent, | ||
// UserAgentOverride: opts.UserAgent, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oof good catch 👍 |
||
// }) | ||
// } | ||
func FalconClientOpts() (out struct { | ||
Cloud string | ||
UserAgent string | ||
}) { | ||
c := strings.ToLower(os.Getenv("CS_CLOUD")) | ||
c = strings.ReplaceAll(c, "-", "") | ||
c = strings.TrimSpace(c) | ||
if c == "" { | ||
c = "us-1" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is very interesting, why does it need to be lowercase for gofalcon but not foundry-fn-go? Its the same github org yah?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is from the go.mod - it's lowercase in gofalcon but capital CS in foundry-fn-go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super weird, curious why that's the case 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK all lower is the convention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we've had users say they have to use the mixed case for
go get
, or it fails, which is super annoying. Ideally it'd be all lowercase. I'll have to figure out what's going on there.