mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-18 13:44:20 +01:00
Username and password support for git_pull addon (#217)
* Add user/password support to git pull. This can be used for private repositories that don't support ssh. Ex: https://cloud.google.com/source-repositories/docs/ * Remove unnecessary err redirection. * Bump git_pull version to 3.1 * Update config.json * Update CHANGELOG.md * Update CHANGELOG.md * address commands
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 4.0
|
||||||
|
- Allow to use user/password authentication for GIT
|
||||||
|
- New options `deployment_user` and `deployment_password`
|
||||||
|
|
||||||
## 3.0
|
## 3.0
|
||||||
- New CLI
|
- New CLI
|
||||||
- Update base image
|
- Update base image
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Git pull",
|
"name": "Git pull",
|
||||||
"version": "3.0",
|
"version": "4.0",
|
||||||
"slug": "git_pull",
|
"slug": "git_pull",
|
||||||
"description": "Simple git pull to update the local configuration",
|
"description": "Simple git pull to update the local configuration",
|
||||||
"url": "https://home-assistant.io/addons/git_pull/",
|
"url": "https://home-assistant.io/addons/git_pull/",
|
||||||
@@ -11,6 +11,8 @@
|
|||||||
"options": {
|
"options": {
|
||||||
"deployment_key": [],
|
"deployment_key": [],
|
||||||
"deployment_key_protocol": "rsa",
|
"deployment_key_protocol": "rsa",
|
||||||
|
"deployment_user": "",
|
||||||
|
"deployment_password": "",
|
||||||
"repository": null,
|
"repository": null,
|
||||||
"auto_restart": false,
|
"auto_restart": false,
|
||||||
"repeat": {
|
"repeat": {
|
||||||
@@ -21,6 +23,8 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"deployment_key": ["str"],
|
"deployment_key": ["str"],
|
||||||
"deployment_key_protocol": "match(rsa|dsa|ecdsa|ed25519|rsa)",
|
"deployment_key_protocol": "match(rsa|dsa|ecdsa|ed25519|rsa)",
|
||||||
|
"deployment_user": "str",
|
||||||
|
"deployment_password": "str",
|
||||||
"repository": "match((?:.+):(\/\/)?(.*?)(\\.git)(\/?|\\#[-\\d\\w._]+?))",
|
"repository": "match((?:.+):(\/\/)?(.*?)(\\.git)(\/?|\\#[-\\d\\w._]+?))",
|
||||||
"auto_restart": "bool",
|
"auto_restart": "bool",
|
||||||
"repeat": {
|
"repeat": {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ CONFIG_PATH=/data/options.json
|
|||||||
|
|
||||||
DEPLOYMENT_KEY=$(jq --raw-output ".deployment_key[]" $CONFIG_PATH)
|
DEPLOYMENT_KEY=$(jq --raw-output ".deployment_key[]" $CONFIG_PATH)
|
||||||
DEPLOYMENT_KEY_PROTOCOL=$(jq --raw-output ".deployment_key_protocol" $CONFIG_PATH)
|
DEPLOYMENT_KEY_PROTOCOL=$(jq --raw-output ".deployment_key_protocol" $CONFIG_PATH)
|
||||||
|
DEPLOYMENT_USER=$(jq --raw-output ".deployment_user" $CONFIG_PATH)
|
||||||
|
DEPLOYMENT_PASSWORD=$(jq --raw-output ".deployment_password" $CONFIG_PATH)
|
||||||
REPOSITORY=$(jq --raw-output '.repository' $CONFIG_PATH)
|
REPOSITORY=$(jq --raw-output '.repository' $CONFIG_PATH)
|
||||||
AUTO_RESTART=$(jq --raw-output '.auto_restart' $CONFIG_PATH)
|
AUTO_RESTART=$(jq --raw-output '.auto_restart' $CONFIG_PATH)
|
||||||
REPEAT_ACTIVE=$(jq --raw-output '.repeat.active' $CONFIG_PATH)
|
REPEAT_ACTIVE=$(jq --raw-output '.repeat.active' $CONFIG_PATH)
|
||||||
@@ -68,6 +70,42 @@ if [ -n "$DEPLOYMENT_KEY" ]; then
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setup-user-password {
|
||||||
|
if [ ! -z "$DEPLOYMENT_USER" ]; then
|
||||||
|
cd /config || return
|
||||||
|
echo "[Info] setting up credential.helper for user: ${DEPLOYMENT_USER}"
|
||||||
|
git config --system credential.helper 'store --file=/tmp/git-credentials'
|
||||||
|
|
||||||
|
# Extract the hostname from repository
|
||||||
|
h="$REPOSITORY"
|
||||||
|
|
||||||
|
# Extract the protocol
|
||||||
|
proto=${h%%://*}
|
||||||
|
|
||||||
|
# Strip the protocol
|
||||||
|
h="${h#*://}"
|
||||||
|
|
||||||
|
# Strip username and password from URL
|
||||||
|
h="${h#*:*@}"
|
||||||
|
h="${h#*@}"
|
||||||
|
|
||||||
|
# Strip the tail of the URL
|
||||||
|
h=${h%%/*}
|
||||||
|
|
||||||
|
# Format the input for git credential commands
|
||||||
|
cred_data="\
|
||||||
|
protocol=${proto}
|
||||||
|
host=${h}
|
||||||
|
username=${DEPLOYMENT_USER}
|
||||||
|
password=${DEPLOYMENT_PASSWORD}
|
||||||
|
"
|
||||||
|
|
||||||
|
# Use git commands to write the credentials to ~/.git-credentials
|
||||||
|
echo "[Info] Saving git credentials to /tmp/git-credentials"
|
||||||
|
git credential fill | git credential approve <<< "$cred_data"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function git-synchronize {
|
function git-synchronize {
|
||||||
if git rev-parse --is-inside-git-dir &>/dev/null
|
if git rev-parse --is-inside-git-dir &>/dev/null
|
||||||
then
|
then
|
||||||
@@ -105,6 +143,7 @@ function validate-config {
|
|||||||
cd /config || { echo "[Error] Failed to cd into /config"; exit 1; }
|
cd /config || { echo "[Error] Failed to cd into /config"; exit 1; }
|
||||||
while true; do
|
while true; do
|
||||||
check-ssh-key
|
check-ssh-key
|
||||||
|
setup-user-password
|
||||||
git-synchronize
|
git-synchronize
|
||||||
validate-config
|
validate-config
|
||||||
# do we repeat?
|
# do we repeat?
|
||||||
|
|||||||
Reference in New Issue
Block a user