Skip to content

andrewoid/apikeys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ApiKey

This library simplifies retrieval of api keys when stored locally and on GitHub.

Dependency

implementation 'com.andrewoid:apikeys:0.4'

Usage

ApiKey apiKey = new ApiKey();
String keyString = apiKey.get();

Storing API Keys Locally

Make sure your .gitignore includes this line

**/apikey.properties

Create a file src/main/resources/apikey.properties in your project. This file must NOT be checked into git.

apikey=ApiKeyGivenToYouByTheApiWhenYouSignUp

Storing API Keys on GitHub

  1. Open your Repository on GitHub and go to Settings

  2. In Secrets and Variables add a new Repository Secret called APIKEY. The value should be the API key that was given to you by the service.

add secret github

Accessing API Keys with GitHub Actions

Pass the API key as an environment variable to your .yaml file as shown below.

env:
    apikey: ${{ secrets.APIKEY }}

pass api key as an environment variable

Accessing more than one API Key

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages