| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 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 | // 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()) |
||
|
|
|||
| 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 { |
||
| 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 { |
||
| 53 | NotFound bool |
||
| 54 | |||
| 55 | Parameter |
||
| 56 | } |
||
| 57 | |||
| 58 | func NewGetParameterResult(o *SDK.GetParameterResponse) *GetParameterResult { |
||
| 59 | result := &GetParameterResult{} |
||
| 60 | if o == nil { |
||
| 61 | return result |
||
| 62 | } |
||
| 63 | result.Parameter = newParameter(o.Parameter) |
||
| 64 | return result |
||
| 65 | } |
||
| 66 |