This library simplifies retrieval of api keys when stored locally and on GitHub.
implementation 'com.andrewoid:apikeys:0.4'ApiKey apiKey = new ApiKey();
String keyString = apiKey.get();Make sure your .gitignore includes this line
**/apikey.propertiesCreate a file src/main/resources/apikey.properties in your project. This file must NOT be checked into git.
apikey=ApiKeyGivenToYouByTheApiWhenYouSignUp
-
Open your Repository on GitHub and go to
Settings -
In
Secrets and Variablesadd a new Repository Secret calledAPIKEY. The value should be the API key that was given to you by the service.
Pass the API key as an environment variable to your .yaml file as shown below.
env:
apikey: ${{ secrets.APIKEY }}If your application needs more than one API Key you can name it something specific in your apikey.properties.
apikey1=ApiKeyGivenToYouByTheApiWhenYouSignUp
apikey2=SecondApiKeyGivenToYouByTheOtherApi
You can retrieve them by
ApiKey apiKey1 = new ApiKey("apikey1");
String keyString1 = apiKey1.get();
ApiKey apiKey2 = new ApiKey("apikey2");
String keyString2 = apiKey2.get();You will need to add two secrets to GitHub with two entries in your .yaml file

