-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7363c69
commit 6b5ed0d
Showing
9 changed files
with
164 additions
and
140 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
|
||
# Configure hook for Livepatch Server | ||
# | ||
# For more information on snap hooks, see: | ||
# https://snapcraft.io/docs/supported-snap-hooks | ||
|
||
. "$SNAP/scripts/manage_config.sh" | ||
|
||
# parse_config: | ||
# As a lot of logic can be done conditionally, | ||
# we aren't using the install hook. The benefit of this | ||
# is it enables users to manually control resets | ||
# of default configurations, directories, etc. | ||
parse_config() { | ||
DEFAULTS_SET=$(snapctl get defaults.set) | ||
|
||
if [ "$DEFAULTS_SET" != "true" ] ; then | ||
echo 'Setting default configuration...' | ||
set_defaults | ||
fi | ||
echo 'Updating candid configuration...' | ||
dump_new_config | ||
|
||
|
||
snapctl restart candid.candidsrv | ||
sleep 3 | ||
} | ||
|
||
parse_config | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# A simple wrapper to check for migrations before | ||
# actively executing them | ||
# TODO: have validation logic for the migrations & check db is actually ready | ||
|
||
if [ -z "$1" ] ; then | ||
echo "Please provide a Postgresql URI and try again." | ||
else | ||
$SNAP/bin/schema-upgrade upgrade $SNAP/bin/migrations --db $1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$1" ] ; then | ||
echo "Please provide a Postgresql URI and try again." | ||
else | ||
$SNAP/bin/schema-upgrade get-version --db $1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/bash | ||
|
||
# Manages configuration for livepatchd | ||
|
||
DEFAULT_CONFIG="$(cat <<EOF | ||
{ | ||
"listen-address": ":8081", | ||
"private-addr": "127.0.0.1", | ||
"location": "http://127.0.0.1:8081", | ||
"storage": { | ||
"type": "memory" | ||
}, | ||
"identity-providers": [ | ||
{ | ||
"type": "static", | ||
"name": "static", | ||
"users": { | ||
"user1": { | ||
"name": "User One", | ||
"email": "user1@example.com", | ||
"password": "password1", | ||
"groups": [ | ||
"group1", | ||
"group3" | ||
] | ||
}, | ||
"user2": { | ||
"name": "User Two", | ||
"email": "user2@example.com", | ||
"password": "password2", | ||
"groups": [ | ||
"group2", | ||
"group3" | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"logging-config": "INFO", | ||
"access-log": "/var/snap/candid/common/logs/candid.access.log", | ||
"resource-path": "/snap/candid/current/www/" | ||
} | ||
EOF | ||
)" | ||
|
||
# Sets the default config in snapd and dumps the file into $SNAP/config | ||
set_defaults() { | ||
echo $( | ||
echo $DEFAULT_CONFIG | | ||
yq -o json | ||
) | xargs -d'\n' -I {} snapctl set -t candid={} | ||
snapctl set defaults.set=true | ||
} | ||
|
||
# Dumps the new config in snapd, to be discovered by livepatchd | ||
dump_new_config() { | ||
# Parses - back to _ for the keys, such that they can be read by livepatchd | ||
snapctl get -d candid | | ||
yq .candid -P --prettyPrint -o yaml > $SNAP_COMMON/config.yaml | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
. "$SNAP/scripts/manage_config.sh" | ||
|
||
echo "Starting candid ..." | ||
"$SNAP/bin/candidsrv $SNAP_COMMON/config.yaml" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters