Skip to content

Commit f739e55

Browse files
authored
add pipeline permissions and checks clients (microsoft#87)
* add pipeline permissions and checks clients * update workflow to use later versions of actions * test removal of dependency step, to see if it downloads on the fly * Revert "test removal of dependency step, to see if it downloads on the fly" This reverts commit 3525b21.
1 parent 809f645 commit f739e55

File tree

5 files changed

+627
-6
lines changed

5 files changed

+627
-6
lines changed

.github/workflows/go.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ jobs:
55
build:
66
name: Build
77
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
go: [ '1.13', '1.14' ]
811
steps:
12+
- name: Check out code into the Go module directory
13+
uses: actions/checkout@v2
914

10-
- name: Set up Go 1.13
11-
uses: actions/setup-go@v1
15+
- name: Setup go
16+
uses: actions/setup-go@v2
1217
with:
13-
go-version: 1.13
18+
go-version: ${{ matrix.go }}
1419
id: go
1520

16-
- name: Check out code into the Go module directory
17-
uses: actions/checkout@v1
18-
1921
- name: Get dependencies
2022
run: |
2123
go get -v -t -d ./...
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// --------------------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------------------------
5+
// Generated file, DO NOT EDIT
6+
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
// --------------------------------------------------------------------------------------------
8+
9+
package pipelinepermissions
10+
11+
import (
12+
"bytes"
13+
"context"
14+
"encoding/json"
15+
"github.com/google/uuid"
16+
"github.com/microsoft/azure-devops-go-api/azuredevops"
17+
"net/http"
18+
)
19+
20+
var ResourceAreaId, _ = uuid.Parse("a81a0441-de52-4000-aa15-ff0e07bfbbaa")
21+
22+
type Client interface {
23+
// [Preview API] Given a ResourceType and ResourceId, returns authorized definitions for that resource.
24+
GetPipelinePermissionsForResource(context.Context, GetPipelinePermissionsForResourceArgs) (*ResourcePipelinePermissions, error)
25+
// [Preview API] Authorizes/Unauthorizes a list of definitions for a given resource.
26+
UpdatePipelinePermisionsForResource(context.Context, UpdatePipelinePermisionsForResourceArgs) (*ResourcePipelinePermissions, error)
27+
// [Preview API] Batch API to authorize/unauthorize a list of definitions for a multiple resources.
28+
UpdatePipelinePermisionsForResources(context.Context, UpdatePipelinePermisionsForResourcesArgs) (*[]ResourcePipelinePermissions, error)
29+
}
30+
31+
type ClientImpl struct {
32+
Client azuredevops.Client
33+
}
34+
35+
func NewClient(ctx context.Context, connection *azuredevops.Connection) (Client, error) {
36+
client, err := connection.GetClientByResourceAreaId(ctx, ResourceAreaId)
37+
if err != nil {
38+
return nil, err
39+
}
40+
return &ClientImpl{
41+
Client: *client,
42+
}, nil
43+
}
44+
45+
// [Preview API] Given a ResourceType and ResourceId, returns authorized definitions for that resource.
46+
func (client *ClientImpl) GetPipelinePermissionsForResource(ctx context.Context, args GetPipelinePermissionsForResourceArgs) (*ResourcePipelinePermissions, error) {
47+
routeValues := make(map[string]string)
48+
if args.Project == nil || *args.Project == "" {
49+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.Project"}
50+
}
51+
routeValues["project"] = *args.Project
52+
if args.ResourceType == nil || *args.ResourceType == "" {
53+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceType"}
54+
}
55+
routeValues["resourceType"] = *args.ResourceType
56+
if args.ResourceId == nil || *args.ResourceId == "" {
57+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceId"}
58+
}
59+
routeValues["resourceId"] = *args.ResourceId
60+
61+
locationId, _ := uuid.Parse("b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2")
62+
resp, err := client.Client.Send(ctx, http.MethodGet, locationId, "5.1-preview.1", routeValues, nil, nil, "", "application/json", nil)
63+
if err != nil {
64+
return nil, err
65+
}
66+
67+
var responseValue ResourcePipelinePermissions
68+
err = client.Client.UnmarshalBody(resp, &responseValue)
69+
return &responseValue, err
70+
}
71+
72+
// Arguments for the GetPipelinePermissionsForResource function
73+
type GetPipelinePermissionsForResourceArgs struct {
74+
// (required) Project ID or project name
75+
Project *string
76+
// (required)
77+
ResourceType *string
78+
// (required)
79+
ResourceId *string
80+
}
81+
82+
// [Preview API] Authorizes/Unauthorizes a list of definitions for a given resource.
83+
func (client *ClientImpl) UpdatePipelinePermisionsForResource(ctx context.Context, args UpdatePipelinePermisionsForResourceArgs) (*ResourcePipelinePermissions, error) {
84+
if args.ResourceAuthorization == nil {
85+
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.ResourceAuthorization"}
86+
}
87+
routeValues := make(map[string]string)
88+
if args.Project == nil || *args.Project == "" {
89+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.Project"}
90+
}
91+
routeValues["project"] = *args.Project
92+
if args.ResourceType == nil || *args.ResourceType == "" {
93+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceType"}
94+
}
95+
routeValues["resourceType"] = *args.ResourceType
96+
if args.ResourceId == nil || *args.ResourceId == "" {
97+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.ResourceId"}
98+
}
99+
routeValues["resourceId"] = *args.ResourceId
100+
101+
body, marshalErr := json.Marshal(*args.ResourceAuthorization)
102+
if marshalErr != nil {
103+
return nil, marshalErr
104+
}
105+
locationId, _ := uuid.Parse("b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2")
106+
resp, err := client.Client.Send(ctx, http.MethodPatch, locationId, "5.1-preview.1", routeValues, nil, bytes.NewReader(body), "application/json", "application/json", nil)
107+
if err != nil {
108+
return nil, err
109+
}
110+
111+
var responseValue ResourcePipelinePermissions
112+
err = client.Client.UnmarshalBody(resp, &responseValue)
113+
return &responseValue, err
114+
}
115+
116+
// Arguments for the UpdatePipelinePermisionsForResource function
117+
type UpdatePipelinePermisionsForResourceArgs struct {
118+
// (required)
119+
ResourceAuthorization *ResourcePipelinePermissions
120+
// (required) Project ID or project name
121+
Project *string
122+
// (required)
123+
ResourceType *string
124+
// (required)
125+
ResourceId *string
126+
}
127+
128+
// [Preview API] Batch API to authorize/unauthorize a list of definitions for a multiple resources.
129+
func (client *ClientImpl) UpdatePipelinePermisionsForResources(ctx context.Context, args UpdatePipelinePermisionsForResourcesArgs) (*[]ResourcePipelinePermissions, error) {
130+
if args.ResourceAuthorizations == nil {
131+
return nil, &azuredevops.ArgumentNilError{ArgumentName: "args.ResourceAuthorizations"}
132+
}
133+
routeValues := make(map[string]string)
134+
if args.Project == nil || *args.Project == "" {
135+
return nil, &azuredevops.ArgumentNilOrEmptyError{ArgumentName: "args.Project"}
136+
}
137+
routeValues["project"] = *args.Project
138+
139+
body, marshalErr := json.Marshal(*args.ResourceAuthorizations)
140+
if marshalErr != nil {
141+
return nil, marshalErr
142+
}
143+
locationId, _ := uuid.Parse("b5b9a4a4-e6cd-4096-853c-ab7d8b0c4eb2")
144+
resp, err := client.Client.Send(ctx, http.MethodPatch, locationId, "5.1-preview.1", routeValues, nil, bytes.NewReader(body), "application/json", "application/json", nil)
145+
if err != nil {
146+
return nil, err
147+
}
148+
149+
var responseValue []ResourcePipelinePermissions
150+
err = client.Client.UnmarshalCollectionBody(resp, &responseValue)
151+
return &responseValue, err
152+
}
153+
154+
// Arguments for the UpdatePipelinePermisionsForResources function
155+
type UpdatePipelinePermisionsForResourcesArgs struct {
156+
// (required)
157+
ResourceAuthorizations *[]ResourcePipelinePermissions
158+
// (required) Project ID or project name
159+
Project *string
160+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// --------------------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT License.
4+
// --------------------------------------------------------------------------------------------
5+
// Generated file, DO NOT EDIT
6+
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7+
// --------------------------------------------------------------------------------------------
8+
9+
package pipelinepermissions
10+
11+
import (
12+
"github.com/google/uuid"
13+
"github.com/microsoft/azure-devops-go-api/azuredevops"
14+
"github.com/microsoft/azure-devops-go-api/azuredevops/pipelineschecks"
15+
"github.com/microsoft/azure-devops-go-api/azuredevops/webapi"
16+
)
17+
18+
type Permission struct {
19+
Authorized *bool `json:"authorized,omitempty"`
20+
AuthorizedBy *webapi.IdentityRef `json:"authorizedBy,omitempty"`
21+
AuthorizedOn *azuredevops.Time `json:"authorizedOn,omitempty"`
22+
}
23+
24+
type PipelinePermission struct {
25+
Authorized *bool `json:"authorized,omitempty"`
26+
AuthorizedBy *webapi.IdentityRef `json:"authorizedBy,omitempty"`
27+
AuthorizedOn *azuredevops.Time `json:"authorizedOn,omitempty"`
28+
Id *int `json:"id,omitempty"`
29+
}
30+
31+
type PipelineProcessResources struct {
32+
Resources *[]PipelineResourceReference `json:"resources,omitempty"`
33+
}
34+
35+
type PipelineResourceReference struct {
36+
Authorized *bool `json:"authorized,omitempty"`
37+
AuthorizedBy *uuid.UUID `json:"authorizedBy,omitempty"`
38+
AuthorizedOn *azuredevops.Time `json:"authorizedOn,omitempty"`
39+
DefinitionId *int `json:"definitionId,omitempty"`
40+
Id *string `json:"id,omitempty"`
41+
Type *string `json:"type,omitempty"`
42+
}
43+
44+
type ResourcePipelinePermissions struct {
45+
AllPipelines *Permission `json:"allPipelines,omitempty"`
46+
Pipelines *[]PipelinePermission `json:"pipelines,omitempty"`
47+
Resource *pipelineschecks.Resource `json:"resource,omitempty"`
48+
}

0 commit comments

Comments
 (0)