|
| 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 | +} |
0 commit comments