functions-framework-go
functions-framework-go copied to clipboard
allow firewall dialog shows under development and testing in macOS
When starting a function for integration testing, the OS always shows a dialog box to confirm we allow opening the firewall.

Is there any way of not having this show ? It disables any chance of scripting and automating integration tests.
It seems that if the localhost:port
as the address for the http.ListenAndServe
, we no longer get the dialog.
https://github.com/GoogleCloudPlatform/functions-framework-go/blob/7ae80f37956ac3a83ee676c63cc4a7a3f753f476/funcframework/framework.go#L106
I think this is a generic warning that can be disabled in settings. I don't think it's specific to this library.
Maybe send a PR if there's a change that doesn't break anything?
Can't really do it unless I disable the firewall completely. The binary keeps changing location (build) when I run tests.
Seems the same issue as in https://github.com/golang/appengine/pull/25 ? Could we do something like that ?
Thanks for linking that issue @picaoao, something similar might work. Above is a PR.
@grant any problems in going forward with the merge ?
@grant any problems in going forward with the merge ?
I need to talk to @grayside and figure out a solution that is appropriate for Go per a comment in the PR. Maybe adding an environment variable.
Comments on the pr at welcome. Pardon the delay.
Comment from @picaoao in https://github.com/GoogleCloudPlatform/functions-framework-go/pull/63#issuecomment-762907726
I think an optional env would be fine. What do you think ?
Hopefully we don't need to introduce an env var to fix this, but as @grayside said in the PR comments, that PR's approach was incorrect.
I'm not familiar enough with Go to suggest a solution for this, maybe propose/prototype a solution and look at the standard solution used by other libraries? Feel free to talk about this here and send a PR after some thought. I can help get the PR through.
Note that as a workaround, you can call http.ListenAndServe
directly. You don't have to use Start
(you can see the function body is very minimal).
@tbpg Not sure how something outside this package could call that directly; the handler is private to this package. It's totally possible I'm missing something :)
Another solution that compliments the existing example might be to have a separate environment variable for host, with the default set to "" so it binds to all addresses if its not provided. It does end up changing the method signature on Start() to include an address, so would likely require a minor version bump.
port := "8080"
host := ""
if envPort := os.Getenv("PORT"); envPort != "" {
port = envPort
}
if envHost := os.Getenv("HOST"); envHost != "" {
host = envHost
}
if err := funcframework.Start(host, port); err != nil {
log.Fatalf("funcframework.Start: %v\n", err)
}
Other minor tweaks might include passing in the entire listen address but I think this approach would be ergonomic, and not force any particular address binding. This way any configuration / development setup / etc could rely on the developers preference (dotenv style, viper, etc)
What I meant was directly replace your call to funcframework.Start
with http.ListenAndServe
.