cloud.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package aci
  14. import (
  15. "context"
  16. "github.com/pkg/errors"
  17. "github.com/docker/compose-cli/aci/login"
  18. )
  19. type aciCloudService struct {
  20. loginService login.AzureLoginService
  21. }
  22. func (cs *aciCloudService) Login(ctx context.Context, params interface{}) error {
  23. opts, ok := params.(LoginParams)
  24. if !ok {
  25. return errors.New("could not read Azure LoginParams struct from generic parameter")
  26. }
  27. if opts.CloudName == "" {
  28. opts.CloudName = login.AzurePublicCloudName
  29. }
  30. if opts.ClientID != "" {
  31. return cs.loginService.LoginServicePrincipal(opts.ClientID, opts.ClientSecret, opts.TenantID, opts.CloudName)
  32. }
  33. return cs.loginService.Login(ctx, opts.TenantID, opts.CloudName)
  34. }
  35. func (cs *aciCloudService) Logout(ctx context.Context) error {
  36. return cs.loginService.Logout(ctx)
  37. }
  38. func (cs *aciCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
  39. contextHelper := newContextCreateHelper()
  40. createOpts := params.(ContextParams)
  41. return contextHelper.createContextData(ctx, createOpts)
  42. }