Skip to content

Commit

Permalink
refactor(snap)!: Drop the support for legacy snap env options (#454)
Browse files Browse the repository at this point in the history
* 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.`

* ci: Reduce dependabot interval to daily

Signed-off-by: Farshid Tavakolizadeh <farshid.tavakolizadeh@canonical.com>
farshidtz authored Jan 18, 2023
1 parent c9f2a05 commit bc7652b
Showing 7 changed files with 24 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -9,4 +9,4 @@ updates:
- package-ecosystem: "gomod"
directory: "/snap/local/helper-go"
schedule:
interval: "weekly"
interval: "daily"
4 changes: 2 additions & 2 deletions .github/workflows/snap.yml
Original file line number Diff line number Diff line change
@@ -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}}

@@ -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: device-mqtt
snap: ${{needs.build.outputs.snap}}
69 changes: 6 additions & 63 deletions snap/local/helper-go/configure.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2021 Canonical Ltd
*
@@ -19,73 +17,18 @@
package main

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

// Deprecated
// ConfToEnv defines mappings from snap config keys to EdgeX environment variable
// names that are used to override individual device-mqtt's [Driver] configuration
// values via a .env file read by the snap service wrapper.
//
// The syntax to set a configuration key is:
//
// env.<section>.<keyname>
//
var ConfToEnv = map[string]string{
// [MQTTBrokerInfo]
"mqttbrokerinfo.schema": "MQTTBROKERINFO_SCHEMA",
"mqttbrokerinfo.host": "MQTTBROKERINFO_HOST",
"mqttbrokerinfo.port": "MQTTBROKERINFO_PORT",
"mqttbrokerinfo.qos": "MQTTBROKERINFO_QOS",
"mqttbrokerinfo.keep-alive": "MQTTBROKERINFO_KEEPALIVE",
"mqttbrokerinfo.client-id": "MQTTBROKERINFO_CLIENTID",

"mqttbrokerinfo.credentials-retry-time": "MQTTBROKERINFO_CREDENTIALSRETRYTIME",
"mqttbrokerinfo.credentials-retry-wait": "MQTTBROKERINFO_CREDENTIALSRETRYWAIT",
"mqttbrokerinfo.conn-establishing-retry": "MQTTBROKERINFO_CONNESTABLISHINGRETRY",
"mqttbrokerinfo.conn-retry-wait-time": "MQTTBROKERINFO_CONNRETRYWAITTIME",

"mqttbrokerinfo.auth-mode": "MQTTBROKERINFO_AUTHMODE",
"mqttbrokerinfo.credentials-path": "MQTTBROKERINFO_CREDENTIALSPATH",

"mqttbrokerinfo.incoming-topic": "MQTTBROKERINFO_INCOMINGTOPIC",
"mqttbrokerinfo.response-topic": "MQTTBROKERINFO_RESPONSETOPIC",

// [Device]
"device.update-last-connected": "DEVICE_UPDATELASTCONNECTED",
"device.use-message-bus": "DEVICE_USEMESSAGEBUS",
}

// configure is called by the main function
func configure() {
const app = "device-mqtt"

log.SetComponentName("configure")

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(app, envJSON, ConfToEnv)
if err != nil {
log.Fatalf("HandleEdgeXConfig failed: %v", err)
}
}

log.Info("Processing config options")
err = options.ProcessConfig(app)
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(app)
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)
}
}
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/edgexfoundry/device-mqtt-go/hooks

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

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=
16 changes: 7 additions & 9 deletions snap/local/helper-go/install.go
Original file line number Diff line number Diff line change
@@ -17,14 +17,14 @@
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.
// installConfig copies all config files from $SNAP to $SNAP_DATA
func installConfig() error {
path := "/config/device-mqtt/res"
path := "/config/" + app + "/res"

err := hooks.CopyDir(
env.Snap+path,
@@ -36,12 +36,10 @@ func installConfig() error {
return nil
}

// 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
@@ -19,6 +19,8 @@ import (
"os"
)

const app = "device-mqtt"

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

0 comments on commit bc7652b

Please sign in to comment.