Skip to content

Commit

Permalink
refactor(snap): option handling and helper-go build
Browse files Browse the repository at this point in the history
Signed-off-by: Farshid Tavakolizadeh <farshid.tavakolizadeh@canonical.com>
  • Loading branch information
farshidtz committed Oct 6, 2022
1 parent d8cdf69 commit 822255d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 53 deletions.
21 changes: 3 additions & 18 deletions snap/local/helper-go/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
GO=GO111MODULE=on go
HOOKS=cmd/configure/configure cmd/install/install
build:
go build -ldflags="-s -w" -o helper-go

tidy:
go mod tidy

build: tidy $(HOOKS)

cmd/configure/configure:
$(GO) build -o $@ ./cmd/configure

cmd/install/install:
$(GO) build -o $@ ./cmd/install

# TODO: fixup unit testing
test:
$(GO) test -coverprofile=coverage.out ./...
$(GO) vet ./...
gofmt -l .
[ "`gofmt -l .`" = "" ]

clean:
rm -f $(HOOKS)
rm -f helper-go
3 changes: 3 additions & 0 deletions snap/local/helper-go/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ func checkSecurityConfig(services []string) ([]string, error) {
}

func configure() {
// process the EdgeX >=2.2 app options
processAppOptions()

var debug = false
var err error
var startServices []string
Expand Down
6 changes: 3 additions & 3 deletions snap/local/helper-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/canonical/edgex-go/hooks

require github.com/canonical/edgex-snap-hooks/v2 v2.4.1
module github.com/edgexfoundry/edgex-go/snap/local/helper-go

go 1.18

require github.com/canonical/edgex-snap-hooks/v2 v2.4.1
2 changes: 0 additions & 2 deletions snap/local/helper-go/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
hooks "github.com/canonical/edgex-snap-hooks/v2"
)

var cli *hooks.CtlCli = hooks.NewSnapCtl()

const secretStoreAddTokensCfg = "env.security-secret-store.add-secretstore-tokens"
const secretStoreAddKnownSecretsCfg = "env.security-secret-store.add-known-secrets"
const consulAddRegistryACLRolesCfg = "env.security-bootstrapper.add-registry-acl-roles"
Expand Down
32 changes: 8 additions & 24 deletions snap/local/helper-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,22 @@ package main

import (
"os"

hooks "github.com/canonical/edgex-snap-hooks/v2"
)

var cli *hooks.CtlCli = hooks.NewSnapCtl()

func main() {
subCommand := os.Args[1]
switch subCommand {
case "install":
case "install": // snap install hook
install()
case "configure":
case "configure": // snap configure hook
configure()
case "options": // apply snap options to apps
options()
default:
panic("Unknown subcommand: " + subCommand)
}
}

// var cli *hooks.CtlCli = hooks.NewSnapCtl()

// func main() {
// // no subcommand, as called by snapd
// if len(os.Args) == 1 {
// // process the EdgeX >=2.2 snap options
// processAppOptions()
// // configure everything else, incl. the legacy snap options
// configure()
// return
// }

// subCommand := os.Args[1]
// switch subCommand {
// case "options":
// // configure options
// options()
// default:
// panic("Unknown CLI sub-command: " + subCommand)
// }
// }
4 changes: 2 additions & 2 deletions snap/local/runtime-helpers/bin/security-proxy-post-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export PATH="$SNAP/bin:$PATH"

# Several config options depend on resources that only exist after proxy
# setup. This re-applies the config options logic after deferred startup:
$SNAP/snap/hooks/configure options --service=security-proxy
$SNAP/bin/helper-go options --service=security-proxy

# Process the EdgeX >=2.2 snap options
$SNAP/snap/hooks/configure options --service=secrets-config
$SNAP/bin/helper-go options --service=secrets-config
7 changes: 3 additions & 4 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,14 @@ parts:
plugin: dump
source: snap/local/runtime-helpers

hooks:
source: snap/local/hooks
helper-go:
source: snap/local/helper-go
plugin: make
after: [go-build-helper]
override-build: |
cd $SNAPCRAFT_PART_SRC
make build
install -DT ./cmd/configure/configure "$SNAPCRAFT_PART_INSTALL/snap/hooks/configure"
install -DT ./cmd/install/install "$SNAPCRAFT_PART_INSTALL/snap/hooks/install"
install -DT ./helper-go $SNAPCRAFT_PART_INSTALL/bin/helper-go
consul:
plugin: nil
Expand Down

0 comments on commit 822255d

Please sign in to comment.