@@ -187,8 +187,9 @@ func (s *Config) Context() context.Context {
187187func (s * Config ) CreateService () (internal.AllServices , error ) {
188188 username := s .GetString ("username" )
189189 password := s .GetString ("password" )
190+ token := s .GetString ("token" )
190191
191- if username == "" || password == "" {
192+ if token == "" && ( username == "" || password == "" ) {
192193 // This might give silghtly unexpected results on OS X, as xdg.ConfigHome points to ~/Library/Application Support
193194 // while we really use/prefer/document ~/.config - which does work on osx as well but won't be displayed here.
194195 configDetails := fmt .Sprintf ("default location %s" , filepath .Join (xdg .ConfigHome , "upctl.yaml" ))
@@ -198,7 +199,16 @@ func (s *Config) CreateService() (internal.AllServices, error) {
198199 return nil , clierrors.MissingCredentialsError {ConfigFile : configDetails }
199200 }
200201
201- client := client .New (username , password , client .WithTimeout (s .ClientTimeout ()))
202+ configs := []client.ConfigFn {
203+ client .WithTimeout (s .ClientTimeout ()),
204+ }
205+ if token != "" {
206+ configs = append (configs , client .WithBearerAuth (token ))
207+ } else {
208+ configs = append (configs , client .WithBasicAuth (username , password ))
209+ }
210+
211+ client := client .New ("" , "" , configs ... )
202212 client .UserAgent = fmt .Sprintf ("upctl/%s" , GetVersion ())
203213
204214 svc := service .New (client )
0 commit comments