Skip to content

Commit

Permalink
feat(snap): add proxy option handling, bump mod
Browse files Browse the repository at this point in the history
Signed-off-by: Farshid Tavakolizadeh <[email protected]>
  • Loading branch information
farshidtz committed Apr 22, 2022
1 parent 4a7468f commit 327cf1d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 29 deletions.
24 changes: 0 additions & 24 deletions snap/local/hooks/cmd/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strings"

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

const ( // iota is reset to 0
Expand Down Expand Up @@ -602,26 +601,3 @@ func configure() {
}
}
}

func configureApps() {
hooks.Info("edgexfoundry:configure Processing apps.* and config.* configuration")
err := snaphookoptions.ProcessAppConfig(
"core-data",
"core-metadata",
"core-command",
"support-notifications",
"support-scheduler",
"app-service-configurable",
"device-virtual",
"security-secret-store",
"security-secretstore-setup",
"security-proxy-setup",
"security-bootstrapper",
"sys-mgmgt-agent")

if err != nil {
hooks.Error(fmt.Sprintf("edgexfoundry:configure could not process options: %v", err))
os.Exit(1)
}

}
5 changes: 3 additions & 2 deletions snap/local/hooks/cmd/configure/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ var cli *hooks.CtlCli = hooks.NewSnapCtl()
func main() {
// no subcommand, as called by snapd
if len(os.Args) == 1 {
// configure everything
// process the EdgeX >=2.2 snap options
processAppOptions()
// configure everything else, incl. the legacy snap options
configure()
configureApps()
return
}

Expand Down
52 changes: 52 additions & 0 deletions snap/local/hooks/cmd/configure/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"

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

func applyConfigOptions(service string) error {
Expand Down Expand Up @@ -60,8 +61,59 @@ func options() {

hooks.Info("edgexfoundry:configure-options: handling config options for a single service: " + *service)

// process the EdgeX >=2.2 snap options
err = app_options.ProcessAppCustomOptions(*service)
if err != nil {
hooks.Error(fmt.Sprintf("edgexfoundry:configure-options: could not process custom options: %v", err))
os.Exit(1)
}

// process the legacy snap options
if err := applyConfigOptions(*service); err != nil {
hooks.Error(fmt.Sprintf("edgexfoundry:configure-options: error handling config options for %s: %v", *service, err))
os.Exit(1)
}
}

func processAppOptions() {
err := app_options.ProcessAppConfig(
"core-data",
"core-metadata",
"core-command",
"support-notifications",
"support-scheduler",
"app-service-configurable",
"device-virtual",
"security-secret-store",
"security-secretstore-setup",
"security-proxy-setup",
"security-bootstrapper",
"sys-mgmgt-agent",
)
if err != nil {
hooks.Error(fmt.Sprintf("edgexfoundry:configure could not process config options: %v", err))
os.Exit(1)
}

// After installation, the configure hook initiates the deferred startup of services,
// processes snap options and exits. The actual services startup happens only
// after the configure hook exits.
//
// The following options should not be processed within the configure hook during
// the initial installation (install-mode=defer-startup). They should be processed
// only on follow-up calls to the configure hook (i.e. when snap set/unset is called)
installMode, err := hooks.NewSnapCtl().Config("install-mode") // this set in the install hook
if err != nil {
hooks.Error(fmt.Sprintf("edgexfoundry:configure failed to read 'install-mode': %s", err))
os.Exit(1)
}
if installMode != "defer-startup" {
err = app_options.ProcessAppCustomOptions(
"secrets-config", // also processed in security-proxy-post-setup.sh
)
if err != nil {
hooks.Error(fmt.Sprintf("edgexfoundry:configure: could not process custom options: %v", err))
os.Exit(1)
}
}
}
3 changes: 2 additions & 1 deletion snap/local/hooks/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module github.com/canonical/edgex-go/hooks

require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2
require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3


go 1.17
4 changes: 2 additions & 2 deletions snap/local/hooks/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2 h1:HMh7QgZaJmlu3kAEGEgr1PJTr8nbfsQSWLmYuWeuPhI=
github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.2/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI=
github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3 h1:kQ7tGjA7k6iAfsvLRKpdoLy0zwsG+4Wqn3DNkbJrhZ8=
github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.3/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
3 changes: 3 additions & 0 deletions snap/local/runtime-helpers/bin/security-proxy-post-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ 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

# Process the EdgeX >=2.2 snap options
$SNAP/snap/hooks/configure options --service=secrets-config

0 comments on commit 327cf1d

Please sign in to comment.