Passed
Pull Request — master (#19)
by eval
01:32
created

ssm.*SSM.PutParameter   A

Complexity

Conditions 3

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nop 2
dl 0
loc 18
rs 9.75
c 0
b 0
f 0
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
// PutParameter executes `PutParameter` operation.
13
func (svc *SSM) PutParameter(ctx context.Context, r PutParameterRequest) (*PutParameterResult, error) {
14
	out, err := svc.RawPutParameter(ctx, r.ToInput())
15
	if err == nil {
16
		return NewPutParameterResult(out), err
17
	}
18
19
	if errors.GetAWSErrorCode(err) == "ParameterAlreadyExists" {
20
		return &PutParameterResult{
21
			AlreadyExists: true,
22
		}, nil
23
	}
24
25
	err = svc.errWrap(errors.ErrorData{
26
		Err:          err,
27
		AWSOperation: "PutParameter",
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
34
// PutParameterRequest has parameters for `PutParameter` operation.
35
type PutParameterRequest struct {
36
	Name  string
37
	Value string
38
39
	// optional
40
	AllowedPattern string
41
	DataType       string
42
	Description    string
43
	KeyID          string
44
	Overwrite      bool
45
	Policies       string
46
	Tags           []Tag
47
	Tier           ParameterTier
48
	Type           ParameterType
49
}
50
51
func (r PutParameterRequest) ToInput() *SDK.PutParameterInput {
0 ignored issues
show
introduced by
exported method PutParameterRequest.ToInput should have comment or be unexported
Loading history...
52
	in := &SDK.PutParameterInput{}
53
	if r.Name != "" {
54
		in.Name = pointers.String(r.Name)
55
	}
56
	if r.Value != "" {
57
		in.Value = pointers.String(r.Value)
58
	}
59
	if r.AllowedPattern != "" {
60
		in.AllowedPattern = pointers.String(r.AllowedPattern)
61
	}
62
	if r.DataType != "" {
63
		in.DataType = pointers.String(r.DataType)
64
	}
65
	if r.Description != "" {
66
		in.Description = pointers.String(r.Description)
67
	}
68
	if r.KeyID != "" {
69
		in.KeyId = pointers.String(r.KeyID)
70
	}
71
	if r.Overwrite {
72
		in.Overwrite = pointers.Bool(r.Overwrite)
73
	}
74
	if r.Policies != "" {
75
		in.Policies = pointers.String(r.Policies)
76
	}
77
78
	if len(r.Tags) != 0 {
79
		list := make([]SDK.Tag, len(r.Tags))
80
		for i, v := range r.Tags {
81
			list[i] = v.ToSDK()
82
		}
83
		in.Tags = list
84
	}
85
	in.Tier = SDK.ParameterTier(r.Tier)
86
	in.Type = SDK.ParameterType(r.Type)
87
	return in
88
}
89
90
type PutParameterResult struct {
0 ignored issues
show
introduced by
exported type PutParameterResult should have comment or be unexported
Loading history...
91
	AlreadyExists bool
92
93
	Tier    ParameterTier
94
	Version int64
95
}
96
97
func NewPutParameterResult(o *SDK.PutParameterResponse) *PutParameterResult {
0 ignored issues
show
introduced by
exported function NewPutParameterResult should have comment or be unexported
Loading history...
98
	result := &PutParameterResult{}
99
	if o == nil {
100
		return result
101
	}
102
103
	result.Tier = ParameterTier(o.Tier)
104
	if o.Version != nil {
105
		result.Version = *o.Version
106
	}
107
	return result
108
}
109