Skip to content

Commit

Permalink
test: configure git for local testing
Browse files Browse the repository at this point in the history
There is a local credential helper and JWT creation utility: this envrc configures git to override the current configuration via environment variables. The local testing server is used instead.
  • Loading branch information
jamestelfer committed Apr 28, 2024
1 parent 8b7424d commit ae0f77c
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions .development/.envrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
#!/bin/sh
#!/bin/bash

# This configuration allows for local testing of the bridge. It uses Git config
# environment variables to override local configuration without making changes
# to it. See https://git-scm.com/docs/git-config#ENVIRONMENT

git_config_add() {
local key="$1"
local value="$2"

index=$(( "${GIT_CONFIG_COUNT:-0}" - 1 ))

# index is incremented each time a setting is added
index=$(( index + 1 ))
export GIT_CONFIG_COUNT=$(( index + 1 ))
export "GIT_CONFIG_KEY_${index}=${key}"
export "GIT_CONFIG_VALUE_${index}=${value}"
}

# default values
export GIT_CONFIG_COUNT=2
export GIT_CONFIG_KEY_0="credential.https://github.com.usehttppath"
export GIT_CONFIG_VALUE_0="true"
helper_path="$(expand_path ../helper)"
export GIT_CONFIG_KEY_1="credential.https://github.com.helper"
export GIT_CONFIG_VALUE_1="${helper_path}/buildkite-connector-credential-helper http://localhost:${SERVER_PORT:-8080}/credential-helper"

# Use the empty string to override helpers from other configuration
# See https://git-scm.com/docs/gitcredentials/2.29.0#Documentation/gitcredentials.txt-helper
git_config_add "credential.helper" ""
git_config_add "credential.https://github.com.helper" ""

# Now configure the testing helper from the this repo. This uses the local JWT
# keys to create an OIDC token that mimics Buildkite's, but doesn't require a
# Buildkite agent. It only works if the server is run with the corresponding
# test keys; see the root .envrc for that information.
git_config_add "credential.https://github.com.helper" "${helper_path}/buildkite-connector-credential-helper http://localhost:${SERVER_PORT:-8080}/git-credentials"
git_config_add "credential.https://github.com.usehttppath" "true"

source_up

Expand All @@ -21,9 +43,15 @@ source_env_if_exists ".envrc.private"
#
# Git diagnostics
#
# Useful git variables for understanding if the credential helper is working.
#

# useful git variables for understanding if the credential helper is working
# trace will show the credential commands that are executed
# export GIT_TRACE=2

# like curl -v, but for git
# export GIT_CURL_VERBOSE=1

# unsure about the value of this one
# export GIT_TRACE_PACKET=1

0 comments on commit ae0f77c

Please sign in to comment.