Automatically set the microgrid (and other) API host/port #342
Replies: 17 comments 5 replies
-
Probably we should align this issue with #191 which is still under discussion |
Beta Was this translation helpful? Give feedback.
-
Whats on my mind here is that user are able to simple configure an app to run against different API endpoints. On a local test system the user might want to point to the cloud sandbox whereas after deployment it points to localhost on the edge controller. However, by default the host and port should be set in the SDK so that there is no config required. The config would only be used as an explicit override imho. |
Beta Was this translation helpful? Give feedback.
-
I think both play well together. The config at the end will come from a config file, which might be written by the cloud sync (production) or by the developer manually (testing). I'm still not sure if (UI) users should be able to change the host/port of the microgrid API via the UI, if they don't, then we don't even have to go through the config system. |
Beta Was this translation helpful? Give feedback.
-
hell no. SECURITY ALERT! :-) |
Beta Was this translation helpful? Give feedback.
-
The more i look at this the more i think this should come from env variables. If there is no UI config there is no strong requirement for this to be in s config file, then env variables are the simplest option and if it becomes annoying we can add support to load them from an Then when can inject the values for each microgrid when building or running the docker image and we are set. |
Beta Was this translation helpful? Give feedback.
-
Sounds like a good first step at least |
Beta Was this translation helpful? Give feedback.
-
Is that convenient for a user that wants to use the SDK locally on his computer without a container against the sandbox and/or if he uses the container locally? I'm not disagreeing just trying to understand how this could potentially work in a local environment / sandbox test environment. What about that if being given in the env variables it would override the default in the SDK or the other way around? |
Beta Was this translation helpful? Give feedback.
-
Yes, very much. And pretty standard.There are plenty of tools to even set these automatically, from cli tools (like
The environment variable always wins. I'm not even sure if the SDK should provide any default. What would be a sensible default? |
Beta Was this translation helpful? Give feedback.
-
So, what I suggest is to keep the current So the SDK def initialize(host = None, port = None, ...):
if host is None:
host = os.getenv("MICROGRID_HOST")
if host is None:
raise InitializationError("Missing MICROGRID_HOST env variable")
if port is None:
port = os.getenv("MICROGRID_PORT")
if port is None:
raise InitializationError("Missing MICROGRID_PORT env variable")
port = int(port) # Also raise if it's not an int
... Alternatively, if we really want to have a SDK provided default: DEFAULT_MICROGRID_HOST = 'localhost'
DEFAULT_MICROGRID_PORT = '9999'
def initialize(host = None, port = None, ...):
if host is None:
host = os.getenv("MICROGRID_HOST", DEFAULT_MICROGRID_HOST)
if port is None:
port = os.getenv("MICROGRID_PORT", DEFAULT_MICROGRID_PORT)
port = int(port)
... |
Beta Was this translation helpful? Give feedback.
-
exactly, yes. |
Beta Was this translation helpful? Give feedback.
-
yeah, also a way to do it. |
Beta Was this translation helpful? Give feedback.
-
IMHO if we are going to provide or open source some real or mock microgrid service that the user can run locally, then it makes sense to provide default that matches the default when running this service in localhost. Otherwise not sure if it makes sense to provide a default, as the user will have to configure it explicitly to some external sandbox anyway and when deploying in controllers it should also always be set explicitly. |
Beta Was this translation helpful? Give feedback.
-
No, thats exactly not the idea. We want to provide a sandbox environment in the cloud where one can run simple or complex simulations with historic data. |
Beta Was this translation helpful? Give feedback.
-
Then users will have to configure the host and port of the sandbox anyway (and probably credentials too), so a default doesn't look very useful. |
Beta Was this translation helpful? Give feedback.
-
Keep in mind we will have to configure many hosts and ports and I'm not sure its a good idea needing to provide them all as env variables. Any thoughts on that? |
Beta Was this translation helpful? Give feedback.
-
True. I think we have 2 types of configuration possible in the SDK. Most dynamic configuration should come from the UI, and should be handled by the But the API config is not something the user needs to know it even exists when using the UI, the UI needs to "inject" these values depending on in which controller an app is being installed on. And this will probably need to be done in The user only need to care about this when doing local development, so it is very useful to have an easy way to override it and point to some sandbox instead. This won't happen with other config variables. |
Beta Was this translation helpful? Give feedback.
-
This will come from environment variables. |
Beta Was this translation helpful? Give feedback.
-
What's needed?
We need the SDK to be able to connect to the microgrid API without SDK users passing them explicitly.
Proposed solution
Load the config from a file. The config file could come from the UI or not depending on if we want to allow this or not. If we don't allow it, we need to have a mechanism to make sure this config file is included when deploying apps.
The user might be able to override this host/port, but it is still undecided. @thomas-nicolai-frequenz mention we should consider the security implications of this before enabling it.
We could also use env variables for this.
Use cases
No response
Alternatives and workarounds
No response
Additional context
This could supersede #40.
Beta Was this translation helpful? Give feedback.
All reactions