Skip to content

Commit

Permalink
Revert "Change of the candid snap." (#198)
Browse files Browse the repository at this point in the history
This reverts commit 6b5ed0d.
  • Loading branch information
kian99 committed Feb 23, 2024
1 parent 4c20c18 commit 505a389
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 139 deletions.
54 changes: 54 additions & 0 deletions snap/local/config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Documentation can be found here: https://github.com/canonical/candid/blob/master/docs/configuration.md

## Server URLs and ports
listen-address: :8081
private-addr: 127.0.0.1
location: 'http://%LOCATION%:8081'

## Persistent storage
# Defaults to non-persistent memory storage, install PostgreSQL or MongoDB
# and configure them below before using this service in production
storage:
type: memory

#storage:
# type: mongodb
# address: 127.0.0.1:27017

#storage:
# type: postgres
# connection-string: postgres://user:pass@localhost/candid

## Identity providers
# Configure this with whatever authentication system you're using
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
logging-config: INFO

## Authentication keys
public-key: %PUBLIC-KEY%
private-key: %PRIVATE-KEY%

admin-agent-public-key: %ADMIN-PUBLIC-KEY%

# Don't change, snap-specific paths
access-log: /var/snap/candid/common/logs/candid.access.log
resource-path: /snap/candid/current/www/
31 changes: 0 additions & 31 deletions snap/local/hooks/configure

This file was deleted.

11 changes: 0 additions & 11 deletions snap/local/scripts/handle_schema_upgrade.sh

This file was deleted.

7 changes: 0 additions & 7 deletions snap/local/scripts/handle_schema_version_check.sh

This file was deleted.

37 changes: 0 additions & 37 deletions snap/local/scripts/manage_config.sh

This file was deleted.

6 changes: 0 additions & 6 deletions snap/local/scripts/wrapper.sh

This file was deleted.

8 changes: 8 additions & 0 deletions snap/local/wrappers/candid
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh -eu
url=$(grep ^location /var/snap/candid/current/config.yaml | cut -d: -f2- | sed "s/[ '\"]//g" || true)

if [ -z "${CANDID_URL:-}" ] && [ -n "${url}" ]; then
export CANDID_URL=${url}
fi

exec candid "$@"
42 changes: 42 additions & 0 deletions snap/local/wrappers/candidsrv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash -eu

CONFIG_FILE="${SNAP_DATA}/config.yaml"
ADMIN_AGENT_FILE="${SNAP_DATA}/admin.keys"

if [ ! -e "$CONFIG_FILE" ]; then
cp "${SNAP}/config/config.yaml" "$CONFIG_FILE"

# replace hostname
hostname="$(hostname -f)"
if [ -n "$hostname" ]; then
sed -i "s#%LOCATION%#${hostname}#g" "$CONFIG_FILE"
fi

# setup keys
key="$(bakery-keygen)"
private_key=$(echo "$key" | jq -r .private)
public_key=$(echo "$key" | jq -r .public)
sed -i "s#%PRIVATE-KEY%#${private_key}#g" "$CONFIG_FILE"
sed -i "s#%PUBLIC-KEY%#${public_key}#g" "$CONFIG_FILE"

# create admin credentials
admin_key="$(bakery-keygen)"
admin_private_key=$(echo "$admin_key" | jq -r .private)
admin_public_key=$(echo "$admin_key" | jq -r .public)
cat >"$ADMIN_AGENT_FILE" <<EOF
{
"key": {
"public": "${admin_public_key}",
"private": "${admin_private_key}"},
"agents": [
{
"url": "http://${hostname}:8081",
"username": "admin@candid"
}
]
}
EOF
sed -i "s#%ADMIN-PUBLIC-KEY%#${admin_public_key}#g" "$CONFIG_FILE"
fi

exec candidsrv "$CONFIG_FILE"
69 changes: 22 additions & 47 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,33 @@ confinement: strict
base: core20
adopt-info: candid # Version our app via set-version within an override

apps:
candidsrv:
command: wrappers/candidsrv
daemon: simple
plugs:
- network
- network-bind
candid:
command: wrappers/candid
plugs:
- home
- network

parts:
# Candid
candid:
plugin: nil
source: ./
source-type: local
organize:
candidsrv: bin/
source: .
source-type: git
build-packages:
- bzr
- gcc
- git
build-snaps:
- go
stage-packages:
- jq
prime:
- bin/bakery-keygen
- bin/candid
Expand Down Expand Up @@ -54,47 +67,9 @@ parts:
mkdir -p $SNAPCRAFT_PART_INSTALL/www/templates
mv ./* $SNAPCRAFT_PART_INSTALL/www/templates
# Dump scripts required to configure candidsrv
scripts:
plugin: dump
source: ./snap/local/scripts
source-type: local
organize:
# Place wrapper in bin such that it can be called easily
wrapper.sh: bin/
manage_config.sh: scripts/
handle_schema_upgrade.sh: bin/
handle_schema_version_check.sh: bin/
filesets:
include:
- bin/wrapper.sh
- scripts/manage_config.sh
- bin/handle_schema_upgrade.sh
- bin/handle_schema_version_check.sh
stage:
- $include

# Dump hooks, allow us to run preliminary hooks if we require such behaviour
hooks:
local:
plugin: dump
source: ./snap/local/hooks
stage-snaps:
- yq
stage-packages:
- jq
organize:
configure: snap/hooks/

apps:
candidsrv:
command: bin/wrapper.sh
daemon: simple
install-mode: disable
plugs:
- "network" # Enables net interface writing (clients)
- "network-bind" # Enables socket binding
candid:
command: bin/candid
plugs:
- home
- network
source: snap/local/
prime:
- config
- wrappers

0 comments on commit 505a389

Please sign in to comment.