Skip to content

Commit

Permalink
Renamed config.ConfigSource to config.Source
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardGomezEscandell committed Oct 26, 2023
1 parent 7a74346 commit 556ef4b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions windows-agent/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func New(ctx context.Context, cachePath string, args ...Option) (m *Config) {
}

// Subscription returns the ProToken and the method it was acquired with (if any).
func (c *Config) Subscription(ctx context.Context) (token string, source ConfigSource, err error) {
func (c *Config) Subscription(ctx context.Context) (token string, source Source, err error) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -141,7 +141,7 @@ func (c *Config) ProvisioningTasks(ctx context.Context, distroName string) ([]ta
}

// SetSubscription overwrites the value of the pro token and the method with which it has been acquired.
func (c *Config) SetSubscription(ctx context.Context, proToken string, source ConfigSource) error {
func (c *Config) SetSubscription(ctx context.Context, proToken string, source Source) error {
c.mu.Lock()
defer c.mu.Unlock()

Expand All @@ -163,7 +163,7 @@ func (c *Config) SetSubscription(ctx context.Context, proToken string, source Co
}

// LandscapeClientConfig returns the value of the landscape server URL.
func (c *Config) LandscapeClientConfig(ctx context.Context) (string, ConfigSource, error) {
func (c *Config) LandscapeClientConfig(ctx context.Context) (string, Source, error) {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down
16 changes: 8 additions & 8 deletions windows-agent/internal/config/config_layering.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package config

import "fmt"

// ConfigSource indicates the method a configuration parameter was acquired.
type ConfigSource int
// Source indicates the method a configuration parameter was acquired.
type Source int

// ConfigSource types.
const (
// SourceNone -> no data.
SourceNone ConfigSource = iota
SourceNone Source = iota

// SourceRegistry -> the data was obtained from the registry.
SourceRegistry
Expand All @@ -27,7 +27,7 @@ type subscription struct {
Checksum string
}

func (s subscription) resolve() (string, ConfigSource) {
func (s subscription) resolve() (string, Source) {
if s.Store != "" {
return s.Store, SourceMicrosoftStore
}
Expand All @@ -43,17 +43,17 @@ func (s subscription) resolve() (string, ConfigSource) {
return "", SourceNone
}

func (s *subscription) Set(src ConfigSource, proToken string) {
func (s *subscription) Set(src Source, proToken string) {
ptr := s.src(src)
*ptr = proToken
}

func (s *subscription) Get(src ConfigSource) string {
func (s *subscription) Get(src Source) string {
return *s.src(src)
}

// src is a helper to avoid duplicationg the mapping in Get and Set.
func (s *subscription) src(src ConfigSource) *string {
func (s *subscription) src(src Source) *string {
switch src {
case SourceNone:
// TODO: Panic? Warning?
Expand All @@ -77,7 +77,7 @@ type landscapeConf struct {
Checksum string
}

func (p landscapeConf) resolve() (string, ConfigSource) {
func (p landscapeConf) resolve() (string, Source) {
if p.GUIConfig != "" {
return p.GUIConfig, SourceGUI
}
Expand Down
4 changes: 2 additions & 2 deletions windows-agent/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestSubscription(t *testing.T) {
settingsState settingsState

wantToken string
wantSource config.ConfigSource
wantSource config.Source
wantError bool
}{
"Success": {settingsState: userTokenHasValue, wantToken: "user_token", wantSource: config.SourceGUI},
Expand Down Expand Up @@ -112,7 +112,7 @@ func TestLandscapeConfig(t *testing.T) {
settingsState settingsState

wantLandscapeConfig string
wantSource config.ConfigSource
wantSource config.Source
wantError bool
}{
"Success": {settingsState: userLandscapeConfigHasValue, wantLandscapeConfig: "[client]\nuser=JohnDoe", wantSource: config.SourceGUI},
Expand Down
4 changes: 2 additions & 2 deletions windows-agent/internal/proservices/landscape/landscape.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type connection struct {

// Config is a configuration provider for ProToken and the Landscape URL.
type Config interface {
LandscapeClientConfig(context.Context) (string, config.ConfigSource, error)
LandscapeClientConfig(context.Context) (string, config.Source, error)

Subscription(context.Context) (string, config.ConfigSource, error)
Subscription(context.Context) (string, config.Source, error)

LandscapeAgentUID(context.Context) (string, error)
SetLandscapeAgentUID(context.Context, string) error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ type mockConfig struct {
mu sync.Mutex
}

func (m *mockConfig) LandscapeClientConfig(ctx context.Context) (string, config.ConfigSource, error) {
func (m *mockConfig) LandscapeClientConfig(ctx context.Context) (string, config.Source, error) {
m.mu.Lock()
defer m.mu.Unlock()

Expand All @@ -812,7 +812,7 @@ func (m *mockConfig) ProvisioningTasks(ctx context.Context, distroName string) (
return nil, nil
}

func (m *mockConfig) Subscription(ctx context.Context) (string, config.ConfigSource, error) {
func (m *mockConfig) Subscription(ctx context.Context) (string, config.Source, error) {
m.mu.Lock()
defer m.mu.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions windows-agent/internal/proservices/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (

// Config is a provider for the subcription configuration.
type Config interface {
SetSubscription(ctx context.Context, token string, source config.ConfigSource) error
SetSubscription(ctx context.Context, token string, source config.Source) error
IsReadOnly() (bool, error)
Subscription(context.Context) (string, config.ConfigSource, error)
Subscription(context.Context) (string, config.Source, error)
FetchMicrosoftStoreSubscription(context.Context) error
}

Expand Down
8 changes: 4 additions & 4 deletions windows-agent/internal/proservices/ui/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ type mockConfig struct {
subscriptionErr bool // Config errors out in Subscription function
fetchErr bool // Config errors out in FetchMicrosoftStoreSubscription function

token string // stores the configured Pro token
source config.ConfigSource // stores the configured subscription source.
token string // stores the configured Pro token
source config.Source // stores the configured subscription source.
}

func (m *mockConfig) SetSubscription(ctx context.Context, token string, source config.ConfigSource) error {
func (m *mockConfig) SetSubscription(ctx context.Context, token string, source config.Source) error {
if m.setSubscriptionErr {
return errors.New("SetSubscription error")
}
Expand All @@ -236,7 +236,7 @@ func (m mockConfig) IsReadOnly() (bool, error) {
}
return m.registryReadOnly, nil
}
func (m mockConfig) Subscription(context.Context) (string, config.ConfigSource, error) {
func (m mockConfig) Subscription(context.Context) (string, config.Source, error) {
if m.subscriptionErr {
return "", config.SourceNone, errors.New("Subscription error")
}
Expand Down

0 comments on commit 556ef4b

Please sign in to comment.