github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azuredevops/azuredevops_provider.go (about) 1 // Copyright 2021 The Terraformer Authors. 2 // 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package azuredevpos 16 17 import ( 18 "errors" 19 "os" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 ) 23 24 type AzureDevOpsProvider struct { //nolint 25 terraformutils.Provider 26 organizationURL string 27 personalAccessToken string 28 } 29 30 func (p *AzureDevOpsProvider) setEnvConfig() error { 31 32 organizationURL := os.Getenv("AZDO_ORG_SERVICE_URL") 33 if organizationURL == "" { 34 return errors.New("environment variable AZDO_ORG_SERVICE_URL missing") 35 } 36 personalAccessToken := os.Getenv("AZDO_PERSONAL_ACCESS_TOKEN") 37 if personalAccessToken == "" { 38 return errors.New("environment variable AZDO_PERSONAL_ACCESS_TOKEN missing") 39 } 40 p.organizationURL = organizationURL 41 p.personalAccessToken = personalAccessToken 42 return nil 43 } 44 45 func (p *AzureDevOpsProvider) Init(args []string) error { 46 err := p.setEnvConfig() 47 if err != nil { 48 return err 49 } 50 return nil 51 } 52 53 func (p *AzureDevOpsProvider) GetName() string { 54 return "azuredevops" 55 } 56 57 func (p *AzureDevOpsProvider) GetProviderData(arg ...string) map[string]interface{} { 58 return map[string]interface{}{} 59 } 60 61 func (p AzureDevOpsProvider) GetResourceConnections() map[string]map[string][]string { 62 supported := p.GetSupportedService() 63 connections := make(map[string]map[string][]string) 64 for serviceName, service := range supported { 65 if service2, ok := service.(AzureDevOpsServiceGenerator); ok { 66 if conn := service2.GetResourceConnections(); conn != nil { 67 connections[serviceName] = conn 68 } 69 } 70 } 71 return connections 72 } 73 74 func (p *AzureDevOpsProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 75 return map[string]terraformutils.ServiceGenerator{ 76 "project": &ProjectGenerator{}, 77 "group": &GroupGenerator{}, 78 "git_repository": &GitRepositoryGenerator{}, 79 } 80 } 81 82 func (p *AzureDevOpsProvider) InitService(serviceName string, verbose bool) error { 83 var isSupported bool 84 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 85 return errors.New("azuredevpos: " + serviceName + " not supported service") 86 } 87 p.Service = p.GetSupportedService()[serviceName] 88 p.Service.SetName(serviceName) 89 p.Service.SetVerbose(verbose) 90 p.Service.SetProviderName(p.GetName()) 91 p.Service.SetArgs(map[string]interface{}{ 92 "organizationURL": p.organizationURL, 93 "personalAccessToken": p.personalAccessToken, 94 }) 95 return nil 96 }