Skip to content

Commit

Permalink
refactor(snap)!: Drop the support for legacy snap env options (#502)
Browse files Browse the repository at this point in the history
* ci(snap): Add snap's Go module to dependabot

* ci(snap): Upgrade to v3 snap testing actions

* refactor(snap)!: Remove support for legacy env options
BREAKING CHANGE: Drop the support for deprecated snap options starting with `env.`

Signed-off-by: Farshid Tavakolizadeh <farshid.tavakolizadeh@canonical.com>
  • Loading branch information
farshidtz authored Jan 18, 2023
1 parent 98ba4b5 commit 33a8a0f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 71 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ updates:
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/snap/local/helper-go"
schedule:
interval: "daily"
4 changes: 2 additions & 2 deletions .github/workflows/snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- name: Build and upload snap
id: build
uses: canonical/edgex-snap-testing/build@v2
uses: canonical/edgex-snap-testing/build@v3
outputs:
snap: ${{steps.build.outputs.snap}}

Expand All @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download and test snap
uses: canonical/edgex-snap-testing/test@v2
uses: canonical/edgex-snap-testing/test@v3
with:
name: app-service-configurable
snap: ${{needs.build.outputs.snap}}
58 changes: 19 additions & 39 deletions snap/local/helper-go/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,32 @@ package main

import (
"fmt"
hooks "github.com/canonical/edgex-snap-hooks/v2"
"github.com/canonical/edgex-snap-hooks/v2/log"
"github.com/canonical/edgex-snap-hooks/v2/options"
"os"

"github.com/canonical/edgex-snap-hooks/v3/env"
"github.com/canonical/edgex-snap-hooks/v3/log"
"github.com/canonical/edgex-snap-hooks/v3/options"
"github.com/canonical/edgex-snap-hooks/v3/snapctl"
)

// validateProfile processes the snap 'profile' configure option, ensuring that the directory
// and associated configuration.toml file in $SNAP_DATA both exist.
//
func validateProfile(prof string) error {
func validateProfile() error {
prof, err := snapctl.Get("profile").Run()
if err != nil {
return fmt.Errorf("error getting snap option: %v", err)
}

log.Debugf("validateProfile: profile is %s", prof)

if prof == "" {
return nil
}

path := fmt.Sprintf("%s/config/res/%s/configuration.toml", hooks.SnapData, prof)
path := fmt.Sprintf("%s/config/res/%s/configuration.toml", env.SnapData, prof)
log.Debugf("validateProfile: checking if %s exists", path)

_, err := os.Stat(path)
_, err = os.Stat(path)
if err != nil {
return fmt.Errorf("profile %s has no configuration.toml", prof)
}
Expand All @@ -46,44 +52,18 @@ func validateProfile(prof string) error {
}

func configure() {

const service = "app-service-configurable"

log.SetComponentName("configure")

log.Info("Processing profile")
prof, err := hooks.NewSnapCtl().Config(hooks.ProfileConfig)
if err != nil {
log.Fatalf("Error reading config 'profile': %v", err)
}

err = validateProfile(prof)
if err != nil {
log.Info("Validating profile configuration")
if err := validateProfile(); err != nil {
log.Fatalf("Error validating profile: %v", err)
}

log.Info("Processing legacy env options")
envJSON, err := hooks.NewSnapCtl().Config(hooks.EnvConfig)
if err != nil {
log.Fatalf("Reading config 'env' failed: %v", err)
}
if envJSON != "" {
log.Debugf("envJSON: %s", envJSON)
err = hooks.HandleEdgeXConfig(service, envJSON, nil)
if err != nil {
log.Fatalf("HandleEdgeXConfig failed: %v", err)
}
}

log.Info("Processing config options")
err = options.ProcessConfig(service)
if err != nil {
log.Fatalf("could not process config options: %v", err)
if err := options.ProcessConfig(app); err != nil {
log.Fatalf("Error processing config options: %v", err)
}

log.Info("Processing autostart options")
err = options.ProcessAutostart(service)
if err != nil {
log.Fatalf("could not process autostart options: %v", err)
if err := options.ProcessAutostart(app); err != nil {
log.Fatalf("Error processing autostart options: %v", err)
}
}
4 changes: 2 additions & 2 deletions snap/local/helper-go/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/edgexfoundry/app-service-configurable/local/helper-go

require github.com/canonical/edgex-snap-hooks/v2 v2.4.1

go 1.18

require github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab
16 changes: 3 additions & 13 deletions snap/local/helper-go/go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
github.com/canonical/edgex-snap-hooks/v2 v2.4.1 h1:TFFF/mHkYTmUd040N8S4q/mp78CUZr1W3Cxx4uRpfOg=
github.com/canonical/edgex-snap-hooks/v2 v2.4.1/go.mod h1:8mjUKSAFNsXYvV0fcfOoYue1dSjTVeJYdaQYtA6pb6Y=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab h1:wpiKN0hX8tqeZNa4jPvgyrqP8ixm1Xu7lcQA3bypR7w=
github.com/canonical/edgex-snap-hooks/v3 v3.0.0-20230112170125-c0580fb68dab/go.mod h1:RvJ48YbdBPZn7L8OcylOpKIlIJD+nMjo5D7WSnPYusY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
21 changes: 6 additions & 15 deletions snap/local/helper-go/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,22 @@
package main

import (
hooks "github.com/canonical/edgex-snap-hooks/v2"
"github.com/canonical/edgex-snap-hooks/v2/env"
"github.com/canonical/edgex-snap-hooks/v2/log"
hooks "github.com/canonical/edgex-snap-hooks/v3"
"github.com/canonical/edgex-snap-hooks/v3/env"
"github.com/canonical/edgex-snap-hooks/v3/log"
)

// installConfig copies all config files from $SNAP to $SNAP_DATA
func installConfig() error {
path := "/config/res"

err := hooks.CopyDir(
env.Snap+path,
env.SnapData+path)
if err != nil {
return err
}

return nil
return hooks.CopyDir(env.Snap+path, env.SnapData+path)
}

// install is called by the main function
func install() {
log.SetComponentName("install")

err := installConfig()
if err != nil {
log.Fatalf("error installing config file: %s", err)
if err := installConfig(); err != nil {
log.Fatalf("Error installing config files: %s", err)
}
}
2 changes: 2 additions & 0 deletions snap/local/helper-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"os"
)

const app = "app-service-configurable"

func main() {
subCommand := os.Args[1]
switch subCommand {
Expand Down

0 comments on commit 33a8a0f

Please sign in to comment.