forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
396 lines (222 loc) · 15.7 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package tfe
import (
"errors"
"fmt"
)
// Generic errors applicable to all resources.
var (
// ErrUnauthorized is returned when receiving a 401.
ErrUnauthorized = errors.New("unauthorized")
// ErrResourceNotFound is returned when receiving a 404.
ErrResourceNotFound = errors.New("resource not found")
// ErrMissingDirectory is returned when the path does not have an existing directory.
ErrMissingDirectory = errors.New("path needs to be an existing directory")
// ErrNamespaceNotAuthorized is returned when a user attempts to perform an action
// on a namespace (organization) they do not have access to.
ErrNamespaceNotAuthorized = errors.New("namespace not authorized")
)
// Options/fields that cannot be defined
var (
ErrUnsupportedOperations = errors.New("operations is deprecated and cannot be specified when execution mode is used")
ErrUnsupportedPrivateKey = errors.New("private Key can only be present with Azure DevOps Server service provider")
ErrUnsupportedBothTagsRegexAndFileTriggersEnabled = errors.New(`"TagsRegex" cannot be populated when "FileTriggersEnabled" is true`)
ErrUnsupportedBothTagsRegexAndTriggerPatterns = errors.New(`"TagsRegex" and "TriggerPrefixes" cannot be populated at the same time`)
ErrUnsupportedBothTagsRegexAndTriggerPrefixes = errors.New(`"TagsRegex" and "TriggerPatterns" cannot be populated at the same time`)
ErrUnsupportedRunTriggerType = errors.New(`"RunTriggerType" must be "inbound" when requesting "include" query params`)
ErrUnsupportedBothTriggerPatternsAndPrefixes = errors.New(`"TriggerPatterns" and "TriggerPrefixes" cannot be populated at the same time`)
ErrUnsupportedBothNamespaceAndPrivateRegistryName = errors.New(`"Namespace" cannot be populated when "RegistryName" is "private"`)
)
// Library errors that usually indicate a bug in the implementation of go-tfe
var (
ErrItemsMustBeSlice = errors.New(`model field "Items" must be a slice`) // ErrItemsMustBeSlice is returned when an API response attribute called Items is not a slice
ErrInvalidRequestBody = errors.New("go-tfe bug: DELETE/PATCH/POST body must be nil, ptr, or ptr slice") // ErrInvalidRequestBody is returned when a request body for DELETE/PATCH/POST is not a reference type
ErrInvalidStructFormat = errors.New("go-tfe bug: struct can't use both json and jsonapi attributes") // ErrInvalidStructFormat is returned when a mix of json and jsonapi tagged fields are used in the same struct
)
// Resource Errors
var (
// ErrWorkspaceLocked is returned when trying to lock a locked workspace.
ErrWorkspaceLocked = errors.New("workspace already locked")
// ErrWorkspaceNotLocked is returned when trying to unlock a unlocked workspace.
ErrWorkspaceNotLocked = errors.New("workspace already unlocked")
// ErrWorkspaceLockedByRun is returned when trying to unlock a workspace locked by a run.
ErrWorkspaceLockedByRun = errors.New("unable to unlock workspace locked by run")
// ErrWorkspaceLockedByTeam is returned when trying to unlock a workspace locked by a team.
ErrWorkspaceLockedByTeam = errors.New("unable to unlock workspace locked by team")
// ErrWorkspaceLockedByUser is returned when trying to unlock a workspace locked by a user.
ErrWorkspaceLockedByUser = errors.New("unable to unlock workspace locked by user")
// ErrWorkspaceLockedStateVersionStillPending is returned when trying to unlock whose
// latest state version is still pending.
ErrWorkspaceLockedStateVersionStillPending = errors.New("unable to unlock workspace while state version upload is still pending")
// ErrWorkspaceStillProcessing is returned when a workspace is still processing state
// to determine if it is safe to delete. "conflict" followed by newline is used to
// preserve go-tfe version compatibility with the error constructed at runtime before it was
// defined here.
ErrWorkspaceStillProcessing = errors.New("conflict\nLatest workspace state is being processed to discover resources, please try again later")
// ErrWorkspaceNotSafeToDelete is returned when a workspace has processed state and
// is determined to still have resources present. "conflict" followed by newline is used to
// preserve go-tfe version compatibility with the error constructed at runtime before it was
// defined here.
ErrWorkspaceNotSafeToDelete = errors.New("conflict\nworkspace cannot be safely deleted because it is still managing resources")
// ErrWorkspaceLockedCannotDelete is returned when a workspace cannot be safely deleted when
// it is locked. "conflict" followed by newline is used to preserve go-tfe version
// compatibility with the error constructed at runtime before it was defined here.
ErrWorkspaceLockedCannotDelete = errors.New("conflict\nWorkspace is currently locked. Workspace must be unlocked before it can be safely deleted")
)
// Invalid values for resources/struct fields
var (
ErrInvalidWorkspaceID = errors.New("invalid value for workspace ID")
ErrInvalidWorkspaceValue = errors.New("invalid value for workspace")
ErrInvalidTerraformVersionID = errors.New("invalid value for terraform version ID")
ErrInvalidTerraformVersionType = errors.New("invalid type for terraform version. Please use 'terraform-version'")
ErrInvalidOPAVersionID = errors.New("invalid value for OPA version ID")
ErrInvalidSentinelVersionID = errors.New("invalid value for Sentinel version ID")
ErrInvalidConfigVersionID = errors.New("invalid value for configuration version ID")
ErrInvalidCostEstimateID = errors.New("invalid value for cost estimate ID")
ErrInvalidSMTPAuth = errors.New("invalid smtp auth type")
ErrInvalidAgentPoolID = errors.New("invalid value for agent pool ID")
ErrInvalidAgentTokenID = errors.New("invalid value for agent token ID")
ErrInvalidRunID = errors.New("invalid value for run ID")
ErrInvalidRunEventID = errors.New("invalid value for run event ID")
ErrInvalidProjectID = errors.New("invalid value for project ID")
ErrInvalidPagination = errors.New("invalid value for page size or number")
ErrInvalidRunTaskCategory = errors.New(`category must be "task"`)
ErrInvalidRunTaskID = errors.New("invalid value for run task ID")
ErrInvalidRunTaskURL = errors.New("invalid url for run task URL")
ErrInvalidWorkspaceRunTaskID = errors.New("invalid value for workspace run task ID")
ErrInvalidWorkspaceRunTaskType = errors.New(`invalid value for type, please use "workspace-tasks"`)
ErrInvalidTaskResultID = errors.New("invalid value for task result ID")
ErrInvalidTaskStageID = errors.New("invalid value for task stage ID")
ErrInvalidApplyID = errors.New("invalid value for apply ID")
ErrInvalidOrg = errors.New("invalid value for organization")
ErrInvalidName = errors.New("invalid value for name")
ErrInvalidNotificationConfigID = errors.New("invalid value for notification configuration ID")
ErrInvalidMembership = errors.New("invalid value for membership")
ErrInvalidMembershipIDs = errors.New("invalid value for organization membership ids")
ErrInvalidOauthClientID = errors.New("invalid value for OAuth client ID")
ErrInvalidOauthTokenID = errors.New("invalid value for OAuth token ID")
ErrInvalidPolicySetID = errors.New("invalid value for policy set ID")
ErrInvalidPolicyCheckID = errors.New("invalid value for policy check ID")
ErrInvalidPolicyEvaluationID = errors.New("invalid value for policy evaluation ID")
ErrInvalidPolicySetOutcomeID = errors.New("invalid value for policy set outcome ID")
ErrInvalidTag = errors.New("invalid tag id")
ErrInvalidPlanExportID = errors.New("invalid value for plan export ID")
ErrInvalidPlanID = errors.New("invalid value for plan ID")
ErrInvalidParamID = errors.New("invalid value for parameter ID")
ErrInvalidPolicyID = errors.New("invalid value for policy ID")
ErrInvalidProvider = errors.New("invalid value for provider")
ErrInvalidVersion = errors.New("invalid value for version")
ErrInvalidRunTriggerID = errors.New("invalid value for run trigger ID")
ErrInvalidRunTriggerType = errors.New(`invalid value or no value for RunTriggerType. It must be either "inbound" or "outbound"`)
ErrInvalidIncludeValue = errors.New(`invalid value for "include" field`)
ErrInvalidSHHKeyID = errors.New("invalid value for SSH key ID")
ErrInvalidStateVerID = errors.New("invalid value for state version ID")
ErrInvalidOutputID = errors.New("invalid value for state version output ID")
ErrInvalidAccessTeamID = errors.New("invalid value for team access ID")
ErrInvalidTeamProjectAccessID = errors.New("invalid value for team project access ID")
ErrInvalidTeamProjectAccessType = errors.New("invalid type for team project access")
ErrInvalidTeamID = errors.New("invalid value for team ID")
ErrInvalidUsernames = errors.New("invalid value for usernames")
ErrInvalidUserID = errors.New("invalid value for user ID")
ErrInvalidUserValue = errors.New("invalid value for user")
ErrInvalidTokenID = errors.New("invalid value for token ID")
ErrInvalidCategory = errors.New("category must be policy-set")
ErrInvalidPolicies = errors.New("must provide at least one policy")
ErrInvalidVariableID = errors.New("invalid value for variable ID")
ErrInvalidNotificationTrigger = errors.New("invalid value for notification trigger")
ErrInvalidVariableSetID = errors.New("invalid variable set ID")
ErrInvalidCommentID = errors.New("invalid value for comment ID")
ErrInvalidCommentBody = errors.New("invalid value for comment body")
ErrInvalidNamespace = errors.New("invalid value for namespace")
ErrInvalidKeyID = errors.New("invalid value for key-id")
ErrInvalidOS = errors.New("invalid value for OS")
ErrInvalidArch = errors.New("invalid value for arch")
ErrInvalidAgentID = errors.New("invalid value for Agent ID")
ErrInvalidModuleID = errors.New("invalid value for module ID")
ErrInvalidRegistryName = errors.New(`invalid value for registry-name. It must be either "private" or "public"`)
ErrInvalidCallbackURL = errors.New("invalid value for callback URL")
ErrInvalidAccessToken = errors.New("invalid value for access token")
ErrInvalidTaskResultsCallbackStatus = fmt.Errorf("invalid value for task result status. Must be either `%s`, `%s`, or `%s`", TaskFailed, TaskPassed, TaskRunning)
)
var (
ErrRequiredAccess = errors.New("access is required")
ErrRequiredAgentPoolID = errors.New("'agent' execution mode requires an agent pool ID to be specified")
ErrRequiredAgentMode = errors.New("specifying an agent pool ID requires 'agent' execution mode")
ErrRequiredBranchWhenTestsEnabled = errors.New("VCS branch is required when enabling tests")
ErrBranchMustBeEmptyWhenTagsEnabled = errors.New("VCS branch must be empty to enable tags")
ErrRequiredCategory = errors.New("category is required")
ErrRequiredDestinationType = errors.New("destination type is required")
ErrRequiredDataType = errors.New("data type is required")
ErrRequiredKey = errors.New("key is required")
ErrRequiredName = errors.New("name is required")
ErrRequiredQuery = errors.New("query cannot be empty")
ErrRequiredEnabled = errors.New("enabled is required")
ErrRequiredEnforce = errors.New("enforce or enforcement-level is required")
ErrConflictingEnforceEnforcementLevel = errors.New("enforce and enforcement-level may not both be specified together")
ErrRequiredEnforcementPath = errors.New("enforcement path is required")
ErrRequiredEnforcementMode = errors.New("enforcement mode is required")
ErrRequiredEmail = errors.New("email is required")
ErrRequiredM5 = errors.New("MD5 is required")
ErrRequiredURL = errors.New("url is required")
ErrRequiredAPIURL = errors.New("API URL is required")
ErrRequiredHTTPURL = errors.New("HTTP URL is required")
ErrRequiredServiceProvider = errors.New("service provider is required")
ErrRequiredProvider = errors.New("provider is required")
ErrRequiredOauthToken = errors.New("OAuth token is required")
ErrRequiredOauthTokenOrGithubAppInstallationID = errors.New("either oauth token ID or github app installation ID is required")
ErrRequiredTestNumber = errors.New("TestNumber is required")
ErrMissingTagIdentifier = errors.New("must specify at least one tag by ID or name")
ErrAgentTokenDescription = errors.New("agent token description can't be blank")
ErrRequiredTagID = errors.New("you must specify at least one tag id to remove")
ErrRequiredTagWorkspaceID = errors.New("you must specify at least one workspace to add tag to")
ErrRequiredWorkspace = errors.New("workspace is required")
ErrRequiredProject = errors.New("project is required")
ErrRequiredWorkspaceID = errors.New("workspace ID is required")
ErrRequiredProjectID = errors.New("project ID is required")
ErrWorkspacesRequired = errors.New("workspaces is required")
ErrWorkspaceMinLimit = errors.New("must provide at least one workspace")
ErrProjectMinLimit = errors.New("must provide at least one project")
ErrRequiredPlan = errors.New("plan is required")
ErrRequiredPolicies = errors.New("policies is required")
ErrRequiredVersion = errors.New("version is required")
ErrRequiredVCSRepo = errors.New("vcs repo is required")
ErrRequiredIdentifier = errors.New("identifier is required")
ErrRequiredDisplayIdentifier = errors.New("display identifier is required")
ErrRequiredSha = errors.New("sha is required")
ErrRequiredSourceable = errors.New("sourceable is required")
ErrRequiredValue = errors.New("value is required")
ErrRequiredOrg = errors.New("organization is required")
ErrRequiredTeam = errors.New("team is required")
ErrRequiredStateVerListOps = errors.New("StateVersionListOptions is required")
ErrRequiredTeamAccessListOps = errors.New("TeamAccessListOptions is required")
ErrRequiredTeamProjectAccessListOps = errors.New("TeamProjectAccessListOptions is required")
ErrRequiredRunTriggerListOps = errors.New("RunTriggerListOptions is required")
ErrRequiredTFVerCreateOps = errors.New("version, URL and sha is required for AdminTerraformVersionCreateOptions")
ErrRequiredOPAVerCreateOps = errors.New("version, URL and sha is required for AdminOPAVersionCreateOptions")
ErrRequiredSentinelVerCreateOps = errors.New("version, URL and sha is required for AdminSentinelVersionCreateOptions")
ErrRequiredSerial = errors.New("serial is required")
ErrRequiredState = errors.New("state is required")
ErrRequiredSHHKeyID = errors.New("SSH key ID is required")
ErrRequiredOnlyOneField = errors.New("only one of usernames or organization membership ids can be provided")
ErrRequiredUsernameOrMembershipIds = errors.New("usernames or organization membership ids are required")
ErrRequiredGlobalFlag = errors.New("global flag is required")
ErrRequiredWorkspacesList = errors.New("no workspaces list provided")
ErrCommentBody = errors.New("comment body is required")
ErrEmptyTeamName = errors.New("team name can not be empty")
ErrInvalidEmail = errors.New("email is invalid")
ErrRequiredPrivateRegistry = errors.New("only private registry is allowed")
ErrRequiredOS = errors.New("OS is required")
ErrRequiredArch = errors.New("arch is required")
ErrRequiredShasum = errors.New("shasum is required")
ErrRequiredFilename = errors.New("filename is required")
ErrInvalidAsciiArmor = errors.New("ASCII Armor is invalid")
ErrRequiredNamespace = errors.New("namespace is required for public registry")
ErrRequiredRegistryModule = errors.New("registry module is required")
ErrRequiredTagBindings = errors.New("TagBindings are required")
ErrInvalidTestRunID = errors.New("invalid value for test run id")
ErrTerraformVersionValidForPlanOnly = errors.New("setting terraform-version is only valid when plan-only is set to true")
ErrStateMustBeOmitted = errors.New("when uploading state, the State and JSONState strings must be omitted from options")
ErrRequiredRawState = errors.New("RawState is required")
ErrStateVersionUploadNotSupported = errors.New("upload not supported by this version of Terraform Enterprise")
)