Skip to content

Make Lambda.env() -> String? public #61

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

Merged
merged 1 commit into from
May 8, 2020
Merged

Conversation

fabianfett
Copy link
Member

Motivation

Developers need to access environment variables quite often at Lambda startup. We want to save them from importing Foundation. 🙃

Changes

This PR makes our internal access env func public.

@fabianfett fabianfett requested a review from tomerd April 23, 2020 16:31
@fabianfett fabianfett force-pushed the public-env-variables branch from 3aa94bb to 6c793c4 Compare April 23, 2020 16:32
@@ -44,6 +44,14 @@ public enum Lambda {
self.run(factory: factory)
}

/// Utility to access/read environment variables
public static func env(_ name: String) -> String? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we nest this under something like Lambda.Utils? not sure...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this would make the code just more verbose. I was even unsure if we should put it under Lambda, since it is namespaced by the package in case someone needs it anyways.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weissi @ktoso @yim-lee wdyt about this? having this exposed as a top level Lambda API is convenient but maybe "too visible"? other option is to expose it via our context. opinions?

Copy link
Contributor

@ktoso ktoso May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not really mind it as such Lambda.env; not having to import Foundation is a nice goal here.
I'd probably document semantics some more but sounds fine.

I'd -1 ....Utils since are magnets for tons of random stuff, at least on Lambda itself one would think twice before adding 10 more random functions 😉

Copy link
Contributor

@yim-lee yim-lee May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest having Lambda.Environment or container of some sort (e.g., env['foo']). Is Lambda.Context a suitable "home" for it?

Otherwise I don't really mind Lambda.env either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Lambda.Context a suitable "home" for it?

Sadly our current Lambda.Context is not available at Lambda initialization, where it is most likely that we need environment variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I was thinking to introduce an InitializationContext which will have this + the eventLoop and potential can grow down the line. I think it will make for a more extensible API anyways?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s right. I’m +1 on the ‘InitializationContext’... But we must be aware that if we expose the env only there, in the simple Lambda.run(closure) use case developers have no way to access the env variable.

Copy link
Contributor

@ktoso ktoso May 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since end variables are IMO used for “global effects” might as well make it globally and easily available — so on the Lambda type statically.

// edit: not really “terrible” global effects, just global effects; config stuff etc; I think it’s useful to have those easy to use when needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay you folks convinced me. @fabianfett would you like to rebase and merge?

@fabianfett fabianfett requested a review from tomerd April 25, 2020 12:57
@ktoso
Copy link
Contributor

ktoso commented May 6, 2020

We want to save them from importing Foundation. 🙃

Noble goal 👍

@tomerd tomerd requested a review from weissi May 6, 2020 18:18
@fabianfett fabianfett force-pushed the public-env-variables branch from 7279bf3 to 5becf01 Compare May 8, 2020 19:30
@tomerd tomerd merged commit b7462b8 into master May 8, 2020
@tomerd tomerd deleted the public-env-variables branch May 8, 2020 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants