github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/azuredevops/azuredevops_service.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  	"context"
    19  	"log"
    20  
    21  	"github.com/microsoft/azure-devops-go-api/azuredevops"
    22  	"github.com/microsoft/azure-devops-go-api/azuredevops/core"
    23  	"github.com/microsoft/azure-devops-go-api/azuredevops/git"
    24  	"github.com/microsoft/azure-devops-go-api/azuredevops/graph"
    25  
    26  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    27  )
    28  
    29  type AzureDevOpsServiceGenerator interface {
    30  	terraformutils.ServiceGenerator
    31  	GetResourceConnections() map[string][]string
    32  }
    33  
    34  type AzureDevOpsService struct { //nolint
    35  	terraformutils.Service
    36  }
    37  
    38  func (az *AzureDevOpsService) GetResourceConnections() map[string][]string {
    39  	return nil
    40  }
    41  
    42  func (az *AzureDevOpsService) getConnection() *azuredevops.Connection {
    43  
    44  	organizationURL := az.Args["organizationURL"].(string)
    45  	personalAccessToken := az.Args["personalAccessToken"].(string)
    46  	return azuredevops.NewPatConnection(organizationURL, personalAccessToken)
    47  }
    48  
    49  func (az *AzureDevOpsService) getCoreClient() (core.Client, error) {
    50  	ctx := context.Background()
    51  	client, err := core.NewClient(ctx, az.getConnection())
    52  	if err != nil {
    53  		log.Println(err)
    54  		return nil, err
    55  	}
    56  	return client, nil
    57  }
    58  
    59  func (az *AzureDevOpsService) getGraphClient() (graph.Client, error) {
    60  	ctx := context.Background()
    61  	client, err := graph.NewClient(ctx, az.getConnection())
    62  	if err != nil {
    63  		log.Println(err)
    64  		return nil, err
    65  	}
    66  	return client, nil
    67  }
    68  
    69  func (az *AzureDevOpsService) getGitClient() (git.Client, error) {
    70  	ctx := context.Background()
    71  	client, err := git.NewClient(ctx, az.getConnection())
    72  	if err != nil {
    73  		log.Println(err)
    74  		return nil, err
    75  	}
    76  	return client, nil
    77  }
    78  
    79  func (az *AzureDevOpsService) appendSimpleResource(id string, resourceName string, resourceType string) {
    80  	newResource := terraformutils.NewSimpleResource(id, resourceName, resourceType, az.ProviderName, []string{})
    81  	az.Resources = append(az.Resources, newResource)
    82  }