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): edgex-snap-hooks related upgrade #101

Merged
merged 2 commits into from
Jul 26, 2022
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
3 changes: 3 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

exec $SNAP/bin/helper-go configure
3 changes: 3 additions & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

exec $SNAP/bin/helper-go install
6 changes: 0 additions & 6 deletions snap/hooks/pre-refresh

This file was deleted.

Empty file removed snap/local/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ BINPATH="${ARGV[0]}"

# binary name == service name/key
SERVICE=$(basename "$BINPATH")
SERVICE_ENV="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env"

if [ -f "$SERVICE_ENV" ]; then
logger "edgex service override: : sourcing $SERVICE_ENV"
source "$SERVICE_ENV"
ENV_FILE="$SNAP_DATA/config/$SERVICE/res/$SERVICE.env"
TAG="edgex-$SERVICE."$(basename "$0")

if [ -f "$ENV_FILE" ]; then
logger --tag=$TAG "sourcing $ENV_FILE"
set -o allexport
source "$ENV_FILE" set
set +o allexport
fi

exec "$@"
10 changes: 10 additions & 0 deletions snap/local/helper-go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

build:
go build -ldflags="-s -w" -o helper-go

tidy:
go mod tidy

clean:
rm -f helper-go

41 changes: 40 additions & 1 deletion snap/local/hooks/const.go → snap/local/helper-go/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
* SPDX-License-Identifier: Apache-2.0'
*/

package hooks
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"
)

// ConfToEnv defines mappings from snap config keys to EdgeX environment variable
// names that are used to override individual device-rfid-llrp's [Device] configuration
Expand Down Expand Up @@ -50,3 +56,36 @@ var ConfToEnv = map[string]string{
// It is especially important to have this configured in the case of larger subnets such as /16 and /8
"app-custom.max-discover-duration-seconds": "APPCUSTOM_MAXDISCOVERDURATIONSECONDS",
}

// configure is called by the main function
func configure() {

const service = "device-rfid-llrp"

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(service, envJSON, ConfToEnv)
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)
}

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

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

go 1.18
13 changes: 7 additions & 6 deletions snap/local/hooks/go.sum → snap/local/helper-go/go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
github.com/canonical/edgex-snap-hooks/v2 v2.2.0 h1:4pDnikrtyrxiynTM49+ppH7hXBx5C7dWUOjEEisCXmI=
github.com/canonical/edgex-snap-hooks/v2 v2.2.0/go.mod h1:rOxrwdYL7hJDhxFH3uV+nVgLPjWOhJWgM5PRD5YG1jI=
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/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/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
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=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
47 changes: 47 additions & 0 deletions snap/local/helper-go/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 Canonical Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*
* SPDX-License-Identifier: Apache-2.0'
*/

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"
)

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

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

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)
}
}
32 changes: 32 additions & 0 deletions snap/local/helper-go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2022 Canonical Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
* SPDX-License-Identifier: Apache-2.0'
*/

package main

import (
"os"
)

func main() {
subCommand := os.Args[1]
switch subCommand {
case "install":
install()
case "configure":
configure()
default:
panic("Unknown subcommand: " + subCommand)
}
}
17 changes: 0 additions & 17 deletions snap/local/hooks/Makefile

This file was deleted.

110 changes: 0 additions & 110 deletions snap/local/hooks/cmd/configure/configure.go

This file was deleted.

Loading