From 802bd089e1317e0f6d140fcc0cd25d599282ac7c Mon Sep 17 00:00:00 2001 From: Siddharth Kochar Date: Mon, 18 Jun 2018 22:18:16 +0530 Subject: [PATCH 1/2] Improved environment variable setup instructions --- README.md | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index e5e27115f..43e33491a 100644 --- a/README.md +++ b/README.md @@ -57,49 +57,36 @@ We appreciate your continued support, thank you! Grab your API Key from the [SendGrid UI](https://app.sendgrid.com/settings/api_keys). -## Setup Environment Variables to Manage Your API Key +## Easily manage API keys using Environment Variables -Do not hard code your [SendGrid API Key](https://app.sendgrid.com/settings/api_keys) into your code. Instead, use something like an [environment variable](http://superuser.com/questions/949560/how-do-i-set-system-environment-variables-in-windows-10) or [Web.config](https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure). +TL;DR: -The examples found below in this quick start and in the example projects all make use of storing their API keys as an environment variable. +Setup Environment Variables in Windows +1. Press Win+R and run SystemPropertiesAdvanced +2. Click on Environment Variables +3. Click New in user variables section +4. Type SENDGRID_API_KEY in the name. (Make sure this name matches the name of key in your code) +5. Type actual API Key in the value +6. Restart the IDE and you're done! -Environment variables are usually part of the OS and are available to programs within that same OS. -It gives the option to bypass hardcoding credentials, making them easy to manage. +Setup Environment Variables using CMD +1. Run CMD as administrator +2. setx SENDGRID_API_KEY "YOUR_API_KEY" -The following example will go through adding an environment variable in Windows 10. +Easily manage your [SendGrid API Keys](https://app.sendgrid.com/settings/api_keys) by storing them into Environment Variables or [Web.config](https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure). It is a good practice to keep your data and configuration settings separate. This way to you can change your SendGrid API key without changing your code. -Looking at the code example from the [Quick Start](#quick_start), we see that the second line of the `Execute()` method tries to retrieve an environment variable like so: +Here are few example to get and set API Keys programatically: +Get Environment Variable ```csharp -var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY"); +var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY"); ``` -`NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY` isn't a variable of your OS environment yet, so let's add it. - -Press `win + R` (or search for "run"), fill in "SystemPropertiesAdvanced", press `enter` and then click "Environment variables". - -You'll get two lists of variables, but we'll focus on the User Variables for this example. - -Click the "New" button beneath the User Variables list. Give it the name `NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY` (or rename the variable in both the environment and code to a more generic name). - -For value, insert your SendGrid API key. Click "Ok", and once again in the Variable Overview and lastly, close the system properties window. - -For other Windows version, you can set an environment variable like this: - +Set Environment Variable ```csharp -var setKey = Environment.SetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY", value); +var setKey = Environment.SetEnvironmentVariable("SENDGRID_API_KEY", "YOUR_API_KEY"); ``` -For example, - -```csharp -var setKey = Environment.SetEnvironmentVariable("SENDGRID_API_KEY", YOUR_API_KEY); -``` - -You may need to restart your IDE to make use of the new variable. - -Now, if all went well, you can access the newly added variable in your C# SendGrid projects! Ready for some examples? - ## Install Package To use SendGrid in your C# project, you can either download the SendGrid C# .NET libraries directly from our Github repository or if you have the NuGet package manager installed, you can grab them automatically: @@ -275,4 +262,4 @@ sendgrid-csharp is guided and supported by the SendGrid [Developer Experience Te sendgrid-csharp is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-csharp are trademarks of SendGrid, Inc. # License -[The MIT License (MIT)](LICENSE.txt) +[The MIT License (MIT)](LICENSE.txt) \ No newline at end of file From 959039437900168f3011032d28d1c4061265c5c2 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 25 Jun 2018 15:39:50 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 43e33491a..abe3e3857 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ # Announcements -## August 2017 - Subscribe to email [notifications](https://dx.sendgrid.com/newsletter/csharp) for releases and breaking changes. @@ -57,11 +55,11 @@ We appreciate your continued support, thank you! Grab your API Key from the [SendGrid UI](https://app.sendgrid.com/settings/api_keys). -## Easily manage API keys using Environment Variables +## Setup Environment Variables to Manage Your API Key -TL;DR: +Manage your [SendGrid API Keys](https://app.sendgrid.com/settings/api_keys) by storing them in Environment Variables or in [Web.config](https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure). It is a good practice to keep your data and configuration settings separate. This way to you can change your SendGrid API key without changing your code. Also, we strongly advise against storing sensitive data directly in your code. -Setup Environment Variables in Windows +Setup Environment Variables using the UI: 1. Press Win+R and run SystemPropertiesAdvanced 2. Click on Environment Variables 3. Click New in user variables section @@ -69,12 +67,10 @@ Setup Environment Variables in Windows 5. Type actual API Key in the value 6. Restart the IDE and you're done! -Setup Environment Variables using CMD +Setup Environment Variables using CMD: 1. Run CMD as administrator 2. setx SENDGRID_API_KEY "YOUR_API_KEY" -Easily manage your [SendGrid API Keys](https://app.sendgrid.com/settings/api_keys) by storing them into Environment Variables or [Web.config](https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure). It is a good practice to keep your data and configuration settings separate. This way to you can change your SendGrid API key without changing your code. - Here are few example to get and set API Keys programatically: Get Environment Variable @@ -262,4 +258,4 @@ sendgrid-csharp is guided and supported by the SendGrid [Developer Experience Te sendgrid-csharp is maintained and funded by SendGrid, Inc. The names and logos for sendgrid-csharp are trademarks of SendGrid, Inc. # License -[The MIT License (MIT)](LICENSE.txt) \ No newline at end of file +[The MIT License (MIT)](LICENSE.txt)