Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pipeline permissions and checks clients #87

Merged
merged 5 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.13', '1.14' ]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up Go 1.13
uses: actions/setup-go@v1
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: 1.13
go-version: ${{ matrix.go }}
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: |
go get -v -t -d ./...
Expand Down
160 changes: 160 additions & 0 deletions azuredevops/pipelinepermissions/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------------------------
// Generated file, DO NOT EDIT
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
// --------------------------------------------------------------------------------------------

package pipelinepermissions

import (
"bytes"
"context"
"encoding/json"
"github.com/google/uuid"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"net/http"
)

var ResourceAreaId, _ = uuid.Parse("a81a0441-de52-4000-aa15-ff0e07bfbbaa")

type Client interface {
// [Preview API] Given a ResourceType and ResourceId, returns authorized definitions for that resource.
GetPipelinePermissionsForResource(context.Context, GetPipelinePermissionsForResourceArgs) (*ResourcePipelinePermissions, error)
// [Preview API] Authorizes/Unauthorizes a list of definitions for a given resource.
UpdatePipelinePermisionsForResource(context.Context, UpdatePipelinePermisionsForResourceArgs) (*ResourcePipelinePermissions, error)
// [Preview API] Batch API to authorize/unauthorize a list of definitions for a multiple resources.
UpdatePipelinePermisionsForResources(context.Context, UpdatePipelinePermisionsForResourcesArgs) (*[]ResourcePipelinePermissions, error)
}

type ClientImpl struct {
Client azuredevops.Client
}

func NewClient(ctx context.Context, connection *azuredevops.Connection) (Client, error) {
client, err := connection.GetClientByResourceAreaId(ctx, ResourceAreaId)
if err != nil {
return nil, err
}
return &ClientImpl{
Client: *client,
}, nil
}

// [Preview API] Given a ResourceType and ResourceId, returns authorized definitions for that resource.
func (client *ClientImpl) GetPipelinePermissionsForResource(ctx context.Context, args GetPipelinePermissionsForResourceArgs) (*ResourcePipelinePermissions, error) {
routeValues := make(map[string]string)
if args.Project == nil || *args.Project == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.Project"}
}
routeValues["project"] = *args.Project
if args.ResourceType == nil || *args.ResourceType == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceType"}
}
routeValues["resourceType"] = *args.ResourceType
if args.ResourceId == nil || *args.ResourceId == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceId"}
}
routeValues["resourceId"] = *args.ResourceId

locationId, _ := uuid.Parse("b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2")
resp, err := client.Client.Send(ctx, http.MethodGet, locationId, "5.1-preview.1", routeValues, nil, nil, "", "application/json", nil)
if err != nil {
return nil, err
}

var responseValue ResourcePipelinePermissions
err = client.Client.UnmarshalBody(resp, &responseValue)
return &responseValue, err
}

// Arguments for the GetPipelinePermissionsForResource function
type GetPipelinePermissionsForResourceArgs struct {
// (required) Project ID or project name
Project *string
// (required)
ResourceType *string
// (required)
ResourceId *string
}

// [Preview API] Authorizes/Unauthorizes a list of definitions for a given resource.
func (client *ClientImpl) UpdatePipelinePermisionsForResource(ctx context.Context, args UpdatePipelinePermisionsForResourceArgs) (*ResourcePipelinePermissions, error) {
if args.ResourceAuthorization == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.ResourceAuthorization"}
}
routeValues := make(map[string]string)
if args.Project == nil || *args.Project == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.Project"}
}
routeValues["project"] = *args.Project
if args.ResourceType == nil || *args.ResourceType == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceType"}
}
routeValues["resourceType"] = *args.ResourceType
if args.ResourceId == nil || *args.ResourceId == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceId"}
}
routeValues["resourceId"] = *args.ResourceId

body, marshalErr := json.Marshal(*args.ResourceAuthorization)
if marshalErr != nil {
return nil, marshalErr
}
locationId, _ := uuid.Parse("b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2")
resp, err := client.Client.Send(ctx, http.MethodPatch, locationId, "5.1-preview.1", routeValues, nil, bytes.NewReader(body), "application/json", "application/json", nil)
if err != nil {
return nil, err
}

var responseValue ResourcePipelinePermissions
err = client.Client.UnmarshalBody(resp, &responseValue)
return &responseValue, err
}

// Arguments for the UpdatePipelinePermisionsForResource function
type UpdatePipelinePermisionsForResourceArgs struct {
// (required)
ResourceAuthorization *ResourcePipelinePermissions
// (required) Project ID or project name
Project *string
// (required)
ResourceType *string
// (required)
ResourceId *string
}

// [Preview API] Batch API to authorize/unauthorize a list of definitions for a multiple resources.
func (client *ClientImpl) UpdatePipelinePermisionsForResources(ctx context.Context, args UpdatePipelinePermisionsForResourcesArgs) (*[]ResourcePipelinePermissions, error) {
if args.ResourceAuthorizations == nil {
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.ResourceAuthorizations"}
}
routeValues := make(map[string]string)
if args.Project == nil || *args.Project == "" {
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.Project"}
}
routeValues["project"] = *args.Project

body, marshalErr := json.Marshal(*args.ResourceAuthorizations)
if marshalErr != nil {
return nil, marshalErr
}
locationId, _ := uuid.Parse("b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2")
resp, err := client.Client.Send(ctx, http.MethodPatch, locationId, "5.1-preview.1", routeValues, nil, bytes.NewReader(body), "application/json", "application/json", nil)
if err != nil {
return nil, err
}

var responseValue []ResourcePipelinePermissions
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
return &responseValue, err
}

// Arguments for the UpdatePipelinePermisionsForResources function
type UpdatePipelinePermisionsForResourcesArgs struct {
// (required)
ResourceAuthorizations *[]ResourcePipelinePermissions
// (required) Project ID or project name
Project *string
}
48 changes: 48 additions & 0 deletions azuredevops/pipelinepermissions/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// --------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// --------------------------------------------------------------------------------------------
// Generated file, DO NOT EDIT
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
// --------------------------------------------------------------------------------------------

package pipelinepermissions

import (
"github.com/google/uuid"
"github.com/microsoft/azure-devops-go-api/azuredevops"
"github.com/microsoft/azure-devops-go-api/azuredevops/pipelineschecks"
"github.com/microsoft/azure-devops-go-api/azuredevops/webapi"
)

type Permission struct {
Authorized *bool `json:"authorized,omitempty"`
AuthorizedBy *webapi.IdentityRef `json:"authorizedBy,omitempty"`
AuthorizedOn *azuredevops.Time `json:"authorizedOn,omitempty"`
}

type PipelinePermission struct {
Authorized *bool `json:"authorized,omitempty"`
AuthorizedBy *webapi.IdentityRef `json:"authorizedBy,omitempty"`
AuthorizedOn *azuredevops.Time `json:"authorizedOn,omitempty"`
Id *int `json:"id,omitempty"`
}

type PipelineProcessResources struct {
Resources *[]PipelineResourceReference `json:"resources,omitempty"`
}

type PipelineResourceReference struct {
Authorized *bool `json:"authorized,omitempty"`
AuthorizedBy *uuid.UUID `json:"authorizedBy,omitempty"`
AuthorizedOn *azuredevops.Time `json:"authorizedOn,omitempty"`
DefinitionId *int `json:"definitionId,omitempty"`
Id *string `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
}

type ResourcePipelinePermissions struct {
AllPipelines *Permission `json:"allPipelines,omitempty"`
Pipelines *[]PipelinePermission `json:"pipelines,omitempty"`
Resource *pipelineschecks.Resource `json:"resource,omitempty"`
}
Loading