-
Notifications
You must be signed in to change notification settings - Fork 37
/
errors.go
84 lines (66 loc) · 2.24 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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package awsbase
import (
"fmt"
"github.com/hashicorp/aws-sdk-go-base/v2/diag"
"github.com/hashicorp/aws-sdk-go-base/v2/internal/config"
)
// cannotAssumeRoleError occurs when AssumeRole cannot complete.
type cannotAssumeRoleError struct {
ar config.AssumeRole
err error
}
func (e cannotAssumeRoleError) Severity() diag.Severity {
return diag.SeverityError
}
func (e cannotAssumeRoleError) Summary() string {
return "Cannot assume IAM Role"
}
func (e cannotAssumeRoleError) Detail() string {
return fmt.Sprintf(`IAM Role (%s) cannot be assumed.
There are a number of possible causes of this - the most common are:
* The credentials used in order to assume the role are invalid
* The credentials do not have appropriate permission to assume the role
* The role ARN is not valid
Error: %s
`, e.ar.RoleARN, e.err)
}
func (e cannotAssumeRoleError) Equal(other diag.Diagnostic) bool {
ed, ok := other.(cannotAssumeRoleError)
if !ok {
return false
}
return ed.Summary() == e.Summary() && ed.Detail() == e.Detail()
}
func (e cannotAssumeRoleError) Err() error {
return e.err
}
func newCannotAssumeRoleError(ar AssumeRole, err error) cannotAssumeRoleError {
return cannotAssumeRoleError{
ar: ar,
err: err,
}
}
var _ diag.DiagnosticWithErr = cannotAssumeRoleError{}
// IsCannotAssumeRoleError returns true if the error contains the CannotAssumeRoleError type.
func IsCannotAssumeRoleError(diag diag.Diagnostic) bool {
_, ok := diag.(cannotAssumeRoleError)
return ok
}
// NoValidCredentialSourcesError occurs when all credential lookup methods have been exhausted without results.
type NoValidCredentialSourcesError = config.NoValidCredentialSourcesError
// IsNoValidCredentialSourcesError returns true if the diagnostic is a NoValidCredentialSourcesError.
func IsNoValidCredentialSourcesError(diag diag.Diagnostic) bool {
_, ok := diag.(NoValidCredentialSourcesError)
return ok
}
// ContainsNoValidCredentialSourcesError returns true if the diagnostics contains a NoValidCredentialSourcesError type.
func ContainsNoValidCredentialSourcesError(diags diag.Diagnostics) bool {
for _, diag := range diags {
if IsNoValidCredentialSourcesError(diag) {
return true
}
}
return false
}