Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(snap)!: Drop the support for legacy snap env options #502

Merged
merged 3 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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