@@ -701,6 +701,10 @@ func (c *Config) BindAuthorization() error {
701701
702702// GetUsername returns the Cumulocity username for the session
703703func (c * Config ) GetUsername () string {
704+ if v := c .GetSessionUsername (); v != "" {
705+ c .Logger .Infof ("Using session username override" )
706+ return v
707+ }
704708 v := c .viper .GetString ("username" )
705709
706710 if v != "" {
@@ -961,6 +965,11 @@ func (c *Config) WritePersistentConfig() error {
961965
962966// GetPassword returns the decrypted password of the current session
963967func (c * Config ) GetPassword () (string , error ) {
968+ if v := c .GetSessionPassword (); v != "" {
969+ c .Logger .Infof ("Using session password override" )
970+ return v , nil
971+ }
972+
964973 value := c .GetPasswordRaw ()
965974
966975 if value == "" {
@@ -1720,16 +1729,32 @@ func ParseLoginTypeWithDefault(v string) string {
17201729
17211730// GetLoginTypeWithDefault get the preferred login type
17221731func (c * Config ) GetLoginTypeWithDefault () string {
1723- v := c .viper . GetString ( SettingsLoginType )
1732+ v := c .GetLoginTypeRaw ( )
17241733 return ParseLoginTypeWithDefault (v )
17251734}
17261735
17271736// GetLoginTypeRaw get the raw value, where it could also be an empty value
17281737func (c * Config ) GetLoginTypeRaw () string {
1738+ if c .HasSessionUsernameOrPassword () {
1739+ // Force BASIC AUTH
1740+ return c8y .LoginTypeBasic
1741+ }
17291742 v := c .viper .GetString (SettingsLoginType )
17301743 return strings .ToUpper (v )
17311744}
17321745
1746+ func (c * Config ) HasSessionUsernameOrPassword () bool {
1747+ return c .GetSessionUsername () != "" || c .GetSessionPassword () != ""
1748+ }
1749+
1750+ func (c * Config ) GetSessionUsername () string {
1751+ return c .viper .GetString ("settings.defaults.sessionUsername" )
1752+ }
1753+
1754+ func (c * Config ) GetSessionPassword () string {
1755+ return c .viper .GetString ("settings.defaults.sessionPassword" )
1756+ }
1757+
17331758// SetLoginType sets the authorization method, e.g. BASIC, OAUTH2_INTERNAL, NONE
17341759func (c * Config ) SetLoginType (v string ) {
17351760 value , err := c8y .ParseLoginType (v )
0 commit comments