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: Secret Provider for all services #134

Merged
merged 5 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func RunAndReturnWaitGroup(

envVars := environment.NewVariables()

configProcessor := config.NewProcessor(lc, commonFlags, envVars, startupTimer, ctx, &wg, configUpdated)
configProcessor := config.NewProcessor(lc, commonFlags, envVars, startupTimer, ctx, &wg, configUpdated, dic)
if err := configProcessor.Process(serviceKey, configStem, serviceConfig); err != nil {
fatalError(err, lc)
}
Expand Down
35 changes: 32 additions & 3 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sync"

"github.com/BurntSushi/toml"
"github.com/edgexfoundry/go-mod-bootstrap/bootstrap/container"
"github.com/edgexfoundry/go-mod-bootstrap/di"
"github.com/edgexfoundry/go-mod-configuration/configuration"
configTypes "github.com/edgexfoundry/go-mod-configuration/pkg/types"
"github.com/edgexfoundry/go-mod-core-contracts/clients/logger"
Expand All @@ -48,6 +50,7 @@ type Processor struct {
ctx context.Context
wg *sync.WaitGroup
configUpdated UpdatedStream
dic *di.Container
overwriteConfig bool
}

Expand All @@ -60,6 +63,7 @@ func NewProcessor(
ctx context.Context,
wg *sync.WaitGroup,
configUpdated UpdatedStream,
dic *di.Container,
) *Processor {
return &Processor{
Logger: lc,
Expand All @@ -69,6 +73,7 @@ func NewProcessor(
ctx: ctx,
wg: wg,
configUpdated: configUpdated,
dic: dic,
}
}

Expand Down Expand Up @@ -283,16 +288,40 @@ func (cp *Processor) listenForChanges(serviceConfig interfaces.Configuration, co
continue
}

previousInsecureSecrets := serviceConfig.GetInsecureSecrets()
previousLogLevel := serviceConfig.GetLogLevel()

if !serviceConfig.UpdateWritableFromRaw(raw) {
lc.Error("ListenForChanges() type check failed")
return
}

currentInsecureSecrets := serviceConfig.GetInsecureSecrets()
currentLogLevel := serviceConfig.GetLogLevel()

lc.Info("Writeable configuration has been updated from the Configuration Provider")
_ = lc.SetLogLevel(serviceConfig.GetLogLevel())

if cp.configUpdated != nil {
cp.configUpdated <- struct{}{}
// Note: Updates occur one setting at a time so only have to look for single changes
switch {
case currentLogLevel != previousLogLevel:
_ = lc.SetLogLevel(serviceConfig.GetLogLevel())
lc.Info(fmt.Sprintf("Logging level changed to %s", currentLogLevel))

lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
// InsecureSecrets (map) will be nil if not in the original TOML used to seed the Config Provider,
// so ignore it if this is the case.
case currentInsecureSecrets != nil &&
!reflect.DeepEqual(currentInsecureSecrets, previousInsecureSecrets):
lc.Info("Insecure Secrets have been updated")
secretProvider := container.SecretProviderFrom(cp.dic.Get)
if secretProvider != nil {
secretProvider.SecretsUpdated()
}

default:
// Signal that configuration updates exists that have not already been processed.
if cp.configUpdated != nil {
cp.configUpdated <- struct{}{}
}
}
}
}
Expand Down
29 changes: 0 additions & 29 deletions bootstrap/container/certificate.go

This file was deleted.

7 changes: 6 additions & 1 deletion bootstrap/container/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ var ConfigurationInterfaceName = di.TypeInstanceToName((*interfaces.Configuratio

// ConfigurationFrom helper function queries the DIC and returns the interfaces.Configuration implementation.
func ConfigurationFrom(get di.Get) interfaces.Configuration {
return get(ConfigurationInterfaceName).(interfaces.Configuration)
configuration := get(ConfigurationInterfaceName)
if configuration != nil {
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
return configuration.(interfaces.Configuration)
}

return (interfaces.Configuration)(nil)
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
}
29 changes: 0 additions & 29 deletions bootstrap/container/credentials.go

This file was deleted.

10 changes: 5 additions & 5 deletions bootstrap/container/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package container

import (
"github.com/edgexfoundry/go-mod-bootstrap/di"

"github.com/edgexfoundry/go-mod-core-contracts/clients/logger"
)

Expand All @@ -25,9 +24,10 @@ var LoggingClientInterfaceName = di.TypeInstanceToName((*logger.LoggingClient)(n

// LoggingClientFrom helper function queries the DIC and returns the logger.loggingClient implementation.
func LoggingClientFrom(get di.Get) logger.LoggingClient {
if loggingClient, ok := get(LoggingClientInterfaceName).(logger.LoggingClient); ok {
return loggingClient
} else {
return nil
loggingClient := get(LoggingClientInterfaceName)
if loggingClient != nil {
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
return loggingClient.(logger.LoggingClient)
}

return (logger.LoggingClient)(nil)
}
19 changes: 12 additions & 7 deletions bootstrap/container/secret.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*******************************************************************************
* Copyright 2019 Dell Inc.
* Copyright 2020 Intel Corp.
*
* 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
Expand All @@ -15,15 +16,19 @@
package container

import (
"github.com/edgexfoundry/go-mod-bootstrap/bootstrap/interfaces"
"github.com/edgexfoundry/go-mod-bootstrap/di"

"github.com/edgexfoundry/go-mod-secrets/pkg"
)

// SecretClientName contains the name of the registry.Client implementation in the DIC.
var SecretClientName = di.TypeInstanceToName((*pkg.SecretClient)(nil))
// SecretProviderName contains the name of the interfaces.SecretProvider implementation in the DIC.
var SecretProviderName = di.TypeInstanceToName((*interfaces.SecretProvider)(nil))

// SecretClientFrom helper function queries the DIC and returns the pkg.SecretClient implementation.
func SecretClientFrom(get di.Get) pkg.SecretClient {
return get(SecretClientName).(pkg.SecretClient)
// SecretProviderFrom helper function queries the DIC and returns the interfaces.SecretProvider
// implementation.
func SecretProviderFrom(get di.Get) interfaces.SecretProvider {
provider := get(SecretProviderName).(interfaces.SecretProvider)
if provider != nil {
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
return provider.(interfaces.SecretProvider)
}
return (interfaces.SecretProvider)(nil)
}
45 changes: 45 additions & 0 deletions bootstrap/container/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright 2020 Intel Corp.
*
* 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.
*******************************************************************************/

package container

import (
"github.com/edgexfoundry/go-mod-bootstrap/di"
"github.com/edgexfoundry/go-mod-secrets/pkg/token/authtokenloader"
"github.com/edgexfoundry/go-mod-secrets/pkg/token/fileioperformer"
)

// FileIoPerformerInterfaceName contains the name of the fileioperformer.FileIoPerformer implementation in the DIC.
var FileIoPerformerInterfaceName = di.TypeInstanceToName((*fileioperformer.FileIoPerformer)(nil))

// FileIoPerformerFrom helper function queries the DIC and returns the fileioperformer.FileIoPerformer implementation.
func FileIoPerformerFrom(get di.Get) fileioperformer.FileIoPerformer {
fileIo := get(FileIoPerformerInterfaceName)
if fileIo != nil {
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
return fileIo.(fileioperformer.FileIoPerformer)
}
return (fileioperformer.FileIoPerformer)(nil)
}

// AuthTokenLoaderInterfaceName contains the name of the authtokenloader.AuthTokenLoader implementation in the DIC.
var AuthTokenLoaderInterfaceName = di.TypeInstanceToName((*authtokenloader.AuthTokenLoader)(nil))

// AuthTokenLoaderFrom helper function queries the DIC and returns the authtokenloader.AuthTokenLoader implementation.
func AuthTokenLoaderFrom(get di.Get) authtokenloader.AuthTokenLoader {
loader := get(AuthTokenLoaderInterfaceName)
if loader != nil {
lenny-goodell marked this conversation as resolved.
Show resolved Hide resolved
return loader.(authtokenloader.AuthTokenLoader)
}
return (authtokenloader.AuthTokenLoader)(nil)
}
16 changes: 7 additions & 9 deletions bootstrap/environment/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ import (
"strconv"
"testing"

"github.com/edgexfoundry/go-mod-secrets/pkg/providers/vault"
"github.com/stretchr/testify/require"
"github.com/edgexfoundry/go-mod-bootstrap/config"

"github.com/edgexfoundry/go-mod-configuration/pkg/types"

"github.com/edgexfoundry/go-mod-core-contracts/clients/logger"
secretsTypes "github.com/edgexfoundry/go-mod-secrets/pkg/types"

"github.com/stretchr/testify/assert"

"github.com/edgexfoundry/go-mod-bootstrap/config"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -327,7 +325,7 @@ func TestOverrideConfigurationExactCase(t *testing.T) {
List: []string{"val1"},
FloatVal: float32(11.11),
SecretStore: config.SecretStoreInfo{
Authentication: vault.AuthenticationInfo{
Authentication: secretsTypes.AuthenticationInfo{
AuthType: "none",
},
},
Expand Down Expand Up @@ -383,7 +381,7 @@ func TestOverrideConfigurationUppercase(t *testing.T) {
List: []string{"val1"},
FloatVal: float32(11.11),
SecretStore: config.SecretStoreInfo{
Authentication: vault.AuthenticationInfo{
Authentication: secretsTypes.AuthenticationInfo{
AuthType: "none",
AuthToken: expectedAuthToken,
},
Expand Down Expand Up @@ -432,7 +430,7 @@ func TestOverrideConfigurationWithBlankValue(t *testing.T) {
List: []string{"val1"},
FloatVal: float32(11.11),
SecretStore: config.SecretStoreInfo{
Authentication: vault.AuthenticationInfo{
Authentication: secretsTypes.AuthenticationInfo{
AuthType: "none",
AuthToken: expectedAuthToken,
},
Expand Down Expand Up @@ -463,7 +461,7 @@ func TestOverrideConfigurationWithEqualInValue(t *testing.T) {
SecretStore config.SecretStoreInfo
}{
SecretStore: config.SecretStoreInfo{
Authentication: vault.AuthenticationInfo{
Authentication: secretsTypes.AuthenticationInfo{
AuthType: "none",
AuthToken: expectedAuthToken,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* the License.
*******************************************************************************/

package httpserver
package handlers

import (
"context"
Expand All @@ -35,8 +35,8 @@ type HttpServer struct {
doListenAndServe bool
}

// NewBootstrap is a factory method that returns an initialized HttpServer receiver struct.
func NewBootstrap(router *mux.Router, doListenAndServe bool) *HttpServer {
// NewHttpServer is a factory method that returns an initialized HttpServer receiver struct.
func NewHttpServer(router *mux.Router, doListenAndServe bool) *HttpServer {
return &HttpServer{
router: router,
isRunning: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* the License.
*******************************************************************************/

package message
package handlers

import (
"context"
Expand All @@ -30,8 +30,8 @@ type StartMessage struct {
version string
}

// NewBootstrap is a factory method that returns an initialized StartMessage receiver struct.
func NewBootstrap(serviceKey, version string) *StartMessage {
// NewStartMessage is a factory method that returns an initialized StartMessage receiver struct.
func NewStartMessage(serviceKey, version string) *StartMessage {
return &StartMessage{
serviceKey: serviceKey,
version: version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* the License.
*******************************************************************************/

package testing
package handlers

import (
"context"
Expand All @@ -33,8 +33,8 @@ type Ready struct {
stream chan<- bool
}

// NewBootstrap is a factory method that returns an initialized Ready receiver struct.
func NewBootstrap(httpServer httpServer, stream chan<- bool) *Ready {
// NewReady is a factory method that returns an initialized Ready receiver struct.
func NewReady(httpServer httpServer, stream chan<- bool) *Ready {
return &Ready{
httpServer: httpServer,
stream: stream,
Expand Down
Loading