diff --git a/snap/local/hooks/cmd/configure/main.go b/snap/local/hooks/cmd/configure/main.go index d1b269d771..5be00c478e 100644 --- a/snap/local/hooks/cmd/configure/main.go +++ b/snap/local/hooks/cmd/configure/main.go @@ -27,7 +27,9 @@ 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() return } diff --git a/snap/local/hooks/cmd/configure/options.go b/snap/local/hooks/cmd/configure/options.go index 2876ec7208..d38567740c 100644 --- a/snap/local/hooks/cmd/configure/options.go +++ b/snap/local/hooks/cmd/configure/options.go @@ -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 { @@ -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) + } + } +} diff --git a/snap/local/hooks/go.mod b/snap/local/hooks/go.mod index 53536ccc94..592ec830e0 100644 --- a/snap/local/hooks/go.mod +++ b/snap/local/hooks/go.mod @@ -1,5 +1,8 @@ module github.com/canonical/edgex-go/hooks -require github.com/canonical/edgex-snap-hooks/v2 v2.1.3 +require github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.5 + +// replace github.com/canonical/edgex-snap-hooks/v2 => ./edgex-snap-hooks +// replace github.com/canonical/edgex-snap-hooks/v2 => github.com/farshidtz/edgex-snap-hooks/v2 d43ccc771100d663099c8ca8e3974d78076b2058 go 1.17 diff --git a/snap/local/hooks/go.sum b/snap/local/hooks/go.sum index 039e14dc08..207bcb21d9 100644 --- a/snap/local/hooks/go.sum +++ b/snap/local/hooks/go.sum @@ -1,5 +1,5 @@ -github.com/canonical/edgex-snap-hooks/v2 v2.1.3 h1:mcV/atn6k6sN6Uik+lSQGEZi4Q6r96epgBW+u6AGZ3Y= -github.com/canonical/edgex-snap-hooks/v2 v2.1.3/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.5 h1:EDFjmHy8CG4T8uFPqD+Per8Hgk250PvRsMgEDCXjYtE= +github.com/canonical/edgex-snap-hooks/v2 v2.2.0-beta.5/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= diff --git a/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh b/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh index 066decdb49..90751a196b 100755 --- a/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh +++ b/snap/local/runtime-helpers/bin/security-proxy-post-setup.sh @@ -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