Passed
Push — master ( 44e67e...3437b8 )
by eval
01:37
created

ssm/client_op_get_parameter.go   A

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 38
dl 0
loc 64
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ssm.NewGetParameterResult 0 7 2
A ssm.GetParameterRequest.ToInput 0 9 3
A ssm.*SSM.GetParameter 0 18 3
1
package ssm
2
3
import (
4
	"context"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/ssm"
7
8
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors"
9
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
10
)
11
12
// GetParameter executes `GetParameter` operation.
13
func (svc *SSM) GetParameter(ctx context.Context, r GetParameterRequest) (*GetParameterResult, error) {
14
	out, err := svc.RawGetParameter(ctx, r.ToInput())
15
	if err == nil {
16
		return NewGetParameterResult(out), err
17
	}
18
19
	if errors.GetAWSErrorCode(err) == "ParameterNotFound" {
20
		return &GetParameterResult{
21
			NotFound: true,
22
		}, nil
23
	}
24
25
	err = svc.errWrap(errors.ErrorData{
26
		Err:          err,
27
		AWSOperation: "GetParameter",
28
	})
29
	svc.Errorf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
30
	return nil, err
31
}
32
33
// GetParameterRequest has parameters for `GetParameter` operation.
34
type GetParameterRequest struct {
35
	Name string
36
37
	// optional
38
	WithDecryption bool
39
}
40
41
func (r GetParameterRequest) ToInput() *SDK.GetParameterInput {
0 ignored issues
show
introduced by
exported method GetParameterRequest.ToInput should have comment or be unexported
Loading history...
42
	in := &SDK.GetParameterInput{}
43
	if r.Name != "" {
44
		in.Name = pointers.String(r.Name)
45
	}
46
	if r.WithDecryption {
47
		in.WithDecryption = pointers.Bool(r.WithDecryption)
48
	}
49
	return in
50
}
51
52
type GetParameterResult struct {
0 ignored issues
show
introduced by
exported type GetParameterResult should have comment or be unexported
Loading history...
53
	NotFound bool
54
55
	Parameter
56
}
57
58
func NewGetParameterResult(o *SDK.GetParameterResponse) *GetParameterResult {
0 ignored issues
show
introduced by
exported function NewGetParameterResult should have comment or be unexported
Loading history...
59
	result := &GetParameterResult{}
60
	if o == nil {
61
		return result
62
	}
63
	result.Parameter = newParameter(o.Parameter)
64
	return result
65
}
66