From 651b06339120a0d522575c97578948e119474281 Mon Sep 17 00:00:00 2001 From: HelpfulStranger999 Date: Wed, 6 Jan 2021 22:31:54 -0600 Subject: [PATCH 1/2] Support multiple targets --- Assets/Secrets/Secrets.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Assets/Secrets/Secrets.cs b/Assets/Secrets/Secrets.cs index c6d9656..347fa5d 100644 --- a/Assets/Secrets/Secrets.cs +++ b/Assets/Secrets/Secrets.cs @@ -11,10 +11,10 @@ public static class Secrets public static string bot_refresh_token; //hai public static void EnvironmentVariables() { - client_id = Environment.GetEnvironmentVariable("client_id"); - client_secret = Environment.GetEnvironmentVariable("client_secret"); - bot_access_token = Environment.GetEnvironmentVariable("bot_access_token"); - bot_refresh_token = Environment.GetEnvironmentVariable("bot_refresh_token"); + client_id = GetVariable("client_id"); + client_secret = GetVariable("client_secret"); + bot_access_token = GetVariable("bot_access_token"); + bot_refresh_token = GetVariable("bot_refresh_token"); /* string value; bool toDelete = false; @@ -37,4 +37,11 @@ public static void EnvironmentVariables() bot_refresh_token = Environment.GetEnvironmentVariable("bot_refresh_token"); */ } + + public static string GetVariable(string name) + { + return Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process) ?? + Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.User) ?? + Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Machine); + } } From 574d2dfd43e1c1e4688b29c287a7264c83d86663 Mon Sep 17 00:00:00 2001 From: HelpfulStranger999 Date: Wed, 6 Jan 2021 23:29:19 -0600 Subject: [PATCH 2/2] Add some basic documentation for the new method Doc style should be standardized, but this is at least something --- Assets/Secrets/Secrets.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/Secrets/Secrets.cs b/Assets/Secrets/Secrets.cs index 347fa5d..7040cb5 100644 --- a/Assets/Secrets/Secrets.cs +++ b/Assets/Secrets/Secrets.cs @@ -38,6 +38,10 @@ public static void EnvironmentVariables() */ } + /// Gets the environment variable at any target level. + /// Attempts to get the environment variable in the order process-wide, user-wide, and finally machine-wide. + /// The name of the environment variable + /// Returns the value of environment variable or null if not found at any level public static string GetVariable(string name) { return Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process) ??