• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

UiPath / uipathcli / 18678624158

21 Oct 2025 09:01AM UTC coverage: 90.797% (-0.08%) from 90.88%
18678624158

push

github

thschmitt
Improve configure command by providing tenant list

499 of 548 new or added lines in 18 files covered. (91.06%)

17 existing lines in 4 files now uncovered.

7044 of 7758 relevant lines covered (90.8%)

1.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.4
/commandline/config_set_command_handler.go
1
package commandline
2

3
import (
4
        "fmt"
5
        "io"
6
        "strings"
7

8
        "github.com/UiPath/uipathcli/config"
9
)
10

11
// configSetCommandHandler implements command for setting config values.
12
//
13
// Example:
14
// uipath config set --key uri --value https://myserver
15
//
16
// The command also supports setting values in different profiles.
17
//
18
// Example:
19
// uipath config set --key uri --value https://myserver --profile onprem
20
type configSetCommandHandler struct {
21
        StdOut         io.Writer
22
        ConfigProvider config.ConfigProvider
23
}
24

25
const successfullySetMessage = "Successfully set config value"
26

27
const ConfigKeyServiceVersion = "serviceVersion"
28
const ConfigKeyOrganization = "organization"
29
const ConfigKeyTenant = "tenant"
30
const ConfigKeyUri = "uri"
31
const ConfigKeyInsecure = "insecure"
32
const ConfigKeyDebug = "debug"
33
const ConfigKeyAuthGrantType = "auth.grantType"
34
const ConfigKeyAuthScopes = "auth.scopes"
35
const ConfigKeyAuthUri = "auth.uri"
36
const ConfigKeyAuthProperties = "auth.properties."
37
const ConfigKeyHeader = "header."
38
const ConfigKeyParameter = "parameter."
39

40
var ConfigKeys = []string{
41
        ConfigKeyServiceVersion,
42
        ConfigKeyOrganization,
43
        ConfigKeyTenant,
44
        ConfigKeyUri,
45
        ConfigKeyInsecure,
46
        ConfigKeyDebug,
47
        ConfigKeyAuthGrantType,
48
        ConfigKeyAuthScopes,
49
        ConfigKeyAuthUri,
50
        ConfigKeyAuthProperties,
51
        ConfigKeyHeader,
52
        ConfigKeyParameter,
53
}
54

55
func (h configSetCommandHandler) Set(key string, value string, profileName string) error {
1✔
56
        cfg := h.getOrCreateProfile(profileName)
1✔
57
        err := h.setConfigValue(&cfg, key, value)
1✔
58
        if err != nil {
2✔
59
                return err
1✔
60
        }
1✔
61
        err = h.ConfigProvider.Update(profileName, cfg)
1✔
62
        if err != nil {
1✔
NEW
63
                return err
×
NEW
64
        }
×
65
        _, _ = fmt.Fprintln(h.StdOut, successfullySetMessage)
1✔
66
        return nil
1✔
67
}
68

69
func (h configSetCommandHandler) setConfigValue(cfg *config.Config, key string, value string) error {
1✔
70
        keyParts := strings.Split(key, ".")
1✔
71
        if key == ConfigKeyServiceVersion {
2✔
72
                cfg.SetServiceVersion(value)
1✔
73
                return nil
1✔
74
        } else if key == ConfigKeyOrganization {
3✔
75
                cfg.SetOrganization(value)
1✔
76
                return nil
1✔
77
        } else if key == ConfigKeyTenant {
3✔
78
                cfg.SetTenant(value)
1✔
79
                return nil
1✔
80
        } else if key == ConfigKeyUri {
3✔
81
                return cfg.SetUri(value)
1✔
82
        } else if key == ConfigKeyInsecure {
3✔
83
                insecure, err := h.convertToBool(value)
1✔
84
                if err != nil {
2✔
85
                        return fmt.Errorf("Invalid value for '%s': %w", ConfigKeyInsecure, err)
1✔
86
                }
1✔
87
                cfg.SetInsecure(insecure)
1✔
88
                return nil
1✔
89
        } else if key == ConfigKeyDebug {
2✔
90
                debug, err := h.convertToBool(value)
1✔
91
                if err != nil {
2✔
92
                        return fmt.Errorf("Invalid value for '%s': %w", ConfigKeyDebug, err)
1✔
93
                }
1✔
94
                cfg.SetDebug(debug)
1✔
95
                return nil
1✔
96
        } else if key == ConfigKeyAuthGrantType {
2✔
97
                cfg.SetAuthGrantType(value)
1✔
98
                return nil
1✔
99
        } else if key == ConfigKeyAuthScopes {
3✔
100
                cfg.SetAuthScopes(value)
1✔
101
                return nil
1✔
102
        } else if key == ConfigKeyAuthUri {
3✔
103
                return cfg.SetAuthUri(value)
1✔
104
        } else if h.isHeaderKey(key, keyParts) {
3✔
105
                cfg.SetHeader(keyParts[1], value)
1✔
106
                return nil
1✔
107
        } else if h.isParameterKey(key, keyParts) {
3✔
108
                cfg.SetParameter(keyParts[1], value)
1✔
109
                return nil
1✔
110
        } else if h.isAuthPropertyKey(key, keyParts) {
3✔
111
                cfg.SetAuthProperty(keyParts[2], value)
1✔
112
                return nil
1✔
113
        }
1✔
114
        return fmt.Errorf("Unknown config key '%s'", key)
1✔
115
}
116

117
func (h configSetCommandHandler) isHeaderKey(key string, keyParts []string) bool {
1✔
118
        return strings.HasPrefix(key, ConfigKeyHeader) && len(keyParts) == 2
1✔
119
}
1✔
120

121
func (h configSetCommandHandler) isParameterKey(key string, keyParts []string) bool {
1✔
122
        return strings.HasPrefix(key, ConfigKeyParameter) && len(keyParts) == 2
1✔
123
}
1✔
124

125
func (h configSetCommandHandler) isAuthPropertyKey(key string, keyParts []string) bool {
1✔
126
        return strings.HasPrefix(key, ConfigKeyAuthProperties) && len(keyParts) == 3
1✔
127
}
1✔
128

129
func (h configSetCommandHandler) convertToBool(value string) (bool, error) {
1✔
130
        if strings.EqualFold(value, "true") {
2✔
131
                return true, nil
1✔
132
        }
1✔
133
        if strings.EqualFold(value, "false") {
1✔
NEW
134
                return false, nil
×
NEW
135
        }
×
136
        return false, fmt.Errorf("Invalid boolean value: %s", value)
1✔
137
}
138

139
func (h configSetCommandHandler) getOrCreateProfile(profileName string) config.Config {
1✔
140
        cfg := h.ConfigProvider.Config(profileName)
1✔
141
        if cfg == nil {
2✔
142
                return h.ConfigProvider.New()
1✔
143
        }
1✔
144
        return *cfg
1✔
145
}
146

147
func newConfigSetCommandHandler(
148
        stdOut io.Writer,
149
        configProvider config.ConfigProvider,
150
) *configSetCommandHandler {
1✔
151
        return &configSetCommandHandler{
1✔
152
                StdOut:         stdOut,
1✔
153
                ConfigProvider: configProvider,
1✔
154
        }
1✔
155
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc