Skip to content

Commit 04cbcf6

Browse files
committed
Write integration test and docs for org_name field
Also favour it over installation IDs. Signed-off-by: Martin Baillie <[email protected]>
1 parent 96ff03f commit 04cbcf6

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ integration-test: integration test ## Run a local development Vault and the inte
177177
# $ make integration-test \
178178
# BASE_URL=https://api.github.com \
179179
# APP_ID=<your application id> \
180-
# INS_ID=<your installation id> \
180+
# ORG_NAME=<org_name> \
181181
# PRV_KEY="$(cat /path/to/your/app/prv_key_file)"
182182
# NOTE: this will automatically skip racyness tests to avoid rate limiting.
183183
.PHONY: integration-test

README.org

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,18 @@ plugin on your personal account if so desired.
216216
7. Click Install App from the LHS. You will be taken to the account installation
217217
pages where you can confirm the app was installed.
218218

219-
8. Note the *Installation ID* from the URL of this page (usually:
220-
https://github.com/settings/installations/<installation id>).
219+
8. (OPTIONAL as of v1.3.0) Note the *Installation ID* from the URL of this page (usually:
220+
https://github.com/settings/installations/<installation id>) if you wish to
221+
configure using the installation ID directly.
221222
#+BEGIN_QUOTE
222223
NOTE: Get the Installation ID anytime: Settings > Developer > settings >
223224
GitHub Apps > Advanced > Payload in Request tab.
224225
#+END_QUOTE
225226

226227
** Setup (Vault)
227-
Using the three key pieces of information from the previous step (Private Key,
228-
App ID and Installation ID), you are ready to move on to setting up the Vault
229-
plugin.
228+
Using the information noted from the previous step (Private Key, App ID and
229+
optionally the Installation ID), you are ready to move on to setting up the
230+
Vault plugin.
230231

231232
1. Move the desired plugin binary into your Vault's configured
232233
=plugin_directory=.
@@ -267,10 +268,13 @@ plugin.
267268
vault secrets enable -path=github -plugin-name=vault-plugin-secrets-github plugin
268269
#+END_SRC
269270

270-
5. Configure the plugin with the details from the previous section.
271+
5. Configure the plugin with the details noted from the previous section.
271272

272273
#+BEGIN_SRC shell
273-
# Write the configuration.
274+
# Write the configuration (discovered installation ID).
275+
vault write /github/config app_id=<app_id> org_name=<org_name> prv_key=@<private_key_file>
276+
277+
# Write the configuration (explicit installation ID).
274278
vault write /github/config app_id=<app_id> ins_id=<installation_id> prv_key=@<private_key_file>
275279

276280
# (OPTIONAL) Confirm the configuration landed as you expected.
@@ -494,12 +498,16 @@ General CRUD operations against the configuration of the plugin.
494498
*** Parameters
495499
- =app_id= (int64) — the Application ID of the GitHub App.
496500
- =ins_id= (int64) — the Installation ID of the GitHub App installation.
501+
- =org_name= (string) — the name of the organisation with the GitHub App installation.
497502
- =private_key= (string) — a private key configured in the GitHub App. This private key must be in PEM PKCS#1 RSAPrivateKey format. It is not returned with read requests for security reasons.
498503
- =base_url= (string) — the base URL for API requests (defaults to the public GitHub API).
499504

500505
*** Examples
501506
#+BEGIN_SRC shell
502-
# Write the plugin configuration using the default base URL and reading the key from a file.
507+
# Write the plugin configuration using the default base URL, reading the key from a file and discovering the installation ID by querying the organisation.
508+
vault write /github/config app_id=123 org_name=my-org [email protected]
509+
510+
# Write the plugin configuration using the default base URL, reading the key from a file and using an explicit installation ID.
503511
vault write /github/config app_id=123 ins_id=456 [email protected]
504512

505513
# Read the plugin configuration.
@@ -572,7 +580,7 @@ make integration test
572580
# NOTE: Keep in mind this test configuration will create real tokens.
573581
make integration test \
574582
BASE_URL=https://api.github.com \
575-
INS_ID=<installation_id> \
583+
ORG_NAME=<org_name> \
576584
APP_ID=<app_id> \
577585
PRV_KEY="$(cat <path_to_app_private_key>)"
578586
#+END_SRC

github/integration_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ var (
2929

3030
// Overridable GitHub App configuration.
3131
appID = envIntOrDefault(keyAppID, testAppID1)
32-
insID = envIntOrDefault(keyInsID, testInsID1)
32+
insID = envIntOrDefault(keyInsID, 0)
33+
orgName = envStrOrDefault(keyOrgName, "")
3334
prvKey = envStrOrDefault(keyPrvKey, testPrvKeyValid)
3435
baseURL = envStrOrDefault(keyBaseURL, "")
3536

@@ -213,6 +214,7 @@ func testWriteConfig(t *testing.T) {
213214
map[string]interface{}{
214215
keyAppID: appID,
215216
keyInsID: insID,
217+
keyOrgName: orgName,
216218
keyPrvKey: prvKey,
217219
keyBaseURL: baseURL,
218220
},
@@ -242,6 +244,7 @@ func testReadConfig(t *testing.T) {
242244
resData := resBody["data"].(map[string]interface{})
243245
assert.Equal(t, resData[keyAppID], float64(appID))
244246
assert.Equal(t, resData[keyInsID], float64(insID))
247+
assert.Equal(t, resData[keyOrgName], orgName)
245248
assert.Equal(t, resData[keyBaseURL], baseURL)
246249
}
247250

0 commit comments

Comments
 (0)