File: endpoint_arn.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.49.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312,636 kB
  • sloc: makefile: 120
file content (104 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (2)
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
package api

import "text/template"

const endpointARNShapeTmplDef = `
{{- define "endpointARNShapeTmpl" }}
{{ range $_, $name := $.MemberNames -}}
	{{ $elem := index $.MemberRefs $name -}}
	{{ if $elem.EndpointARN -}}
		func (s *{{ $.ShapeName }}) getEndpointARN() (arn.Resource, error) {
			if s.{{ $name }} == nil {
				return nil, fmt.Errorf("member {{ $name }} is nil")
			}
			return parseEndpointARN(*s.{{ $name }})
		}

		func (s *{{ $.ShapeName }}) hasEndpointARN() bool {
			if s.{{ $name }} == nil {
				return false
			}
			return arn.IsARN(*s.{{ $name }})
		}

		// updateArnableField updates the value of the input field that 
		// takes an ARN as an input. This method is useful to backfill 
		// the parsed resource name from ARN into the input member.
		// It returns a pointer to a modified copy of input and an error.
		// Note that original input is not modified. 
		func (s {{ $.ShapeName }}) updateArnableField(v string) (interface{}, error) {
			if s.{{ $name }} == nil {
				return nil, fmt.Errorf("member {{ $name }} is nil")
			}
			s.{{ $name }} = aws.String(v)
			return &s, nil 
		}
	{{ end -}}
{{ end }}
{{ end }}
`

var endpointARNShapeTmpl = template.Must(
	template.New("endpointARNShapeTmpl").
		Parse(endpointARNShapeTmplDef),
)

const outpostIDShapeTmplDef = `
{{- define "outpostIDShapeTmpl" }}
{{ range $_, $name := $.MemberNames -}}
	{{ $elem := index $.MemberRefs $name -}}
	{{ if $elem.OutpostIDMember -}}
		func (s *{{ $.ShapeName }}) getOutpostID() (string, error) {
			if s.{{ $name }} == nil {
				return "", fmt.Errorf("member {{ $name }} is nil")
			}
			return *s.{{ $name }}, nil
		}

		func (s *{{ $.ShapeName }}) hasOutpostID() bool {
			if s.{{ $name }} == nil {
				return false
			}
			return true 
		}
	{{ end -}}
{{ end }}
{{ end }}
`

var outpostIDShapeTmpl = template.Must(
	template.New("outpostIDShapeTmpl").
		Parse(outpostIDShapeTmplDef),
)

const accountIDWithARNShapeTmplDef = `
{{- define "accountIDWithARNShapeTmpl" }}
{{ range $_, $name := $.MemberNames -}}
	{{ $elem := index $.MemberRefs $name -}}
	{{ if $elem.AccountIDMemberWithARN -}}
		{{ $FunctionName := $name }}
		{{ if eq $name "AccountId" }}
  		{{ $FunctionName = "AccountID" }}
		{{ end }}
		// update{{ $FunctionName }} returns a pointer to a modified copy of input,
		// if account id is not provided, we update the account id in modified input
		// if account id is provided, but doesn't match with the one in ARN, we throw an error
		// if account id is not updated, we return nil. Note that original input is not modified. 
		func (s {{ $.ShapeName }}) update{{ $FunctionName }}(accountId string) (interface{}, error) {
			if s.{{ $name }} == nil {
				s.{{ $name }} = aws.String(accountId)
				return &s, nil
			} else if *s.{{ $name }} != accountId  {
				return &s, fmt.Errorf("Account ID mismatch, the Account ID cannot be specified in an ARN and in the accountId field")
			}
			return nil, nil
		}
	{{ end -}}
{{ end }}
{{ end }}
`

var accountIDWithARNShapeTmpl = template.Must(
	template.New("accountIDWithARNShapeTmpl").
		Parse(accountIDWithARNShapeTmplDef),
)