forked from aws-beam/aws-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.ex
More file actions
104 lines (86 loc) · 2.97 KB
/
Copy pathutil.ex
File metadata and controls
104 lines (86 loc) · 2.97 KB
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
defmodule AWS.CodeGen.Util do
def service_docs(service) do
with "<p></p>" <- service["traits"]["smithy.api#documentation"], do: ""
end
def get_json_version(service) do
traits = service["traits"]
["aws.protocols#" <> protocol | _] =
Enum.filter(Map.keys(traits), &String.starts_with?(&1, "aws.protocols#"))
case protocol do
## TODO: according to the docs this should result in application/json but our current code will make it application/x-amz-json-1.1
"restJson1" -> "1.1"
"awsJson1_0" -> "1.0"
"awsJson1_1" -> "1.1"
"awsQuery" -> nil
"restXml" -> nil
"ec2Query" -> nil
end
end
def get_signature_version(service) do
traits = service["traits"]
signature = Enum.filter(Map.keys(traits), &String.starts_with?(&1, "aws.auth#"))
case signature do
["aws.auth#sig" <> version] -> version
["aws.auth#sigv4", "aws.auth#sigv4a"] -> "aws.auth#sigv4"
[] -> nil
end
end
def get_service_id(service) do
service["traits"]["aws.api#service"]["sdkId"]
end
@doc """
Derive the AWS-canonical service-specific endpoint env var name from the
service's `sdkId` (a.k.a. `service_id`).
Per https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-endpoints.html
the env var suffix is the `sdkId` with spaces replaced by `_` and the
whole string uppercased. The generic prefix is `AWS_ENDPOINT_URL_`.
Examples:
iex> AWS.CodeGen.Util.endpoint_url_env_var(%{"traits" => %{"aws.api#service" => %{"sdkId" => "DynamoDB"}}})
"AWS_ENDPOINT_URL_DYNAMODB"
iex> AWS.CodeGen.Util.endpoint_url_env_var(%{"traits" => %{"aws.api#service" => %{"sdkId" => "Elastic Beanstalk"}}})
"AWS_ENDPOINT_URL_ELASTIC_BEANSTALK"
iex> AWS.CodeGen.Util.endpoint_url_env_var(%{"traits" => %{"aws.api#service" => %{"sdkId" => "CloudTrail Data"}}})
"AWS_ENDPOINT_URL_CLOUDTRAIL_DATA"
"""
def endpoint_url_env_var(service) do
case get_service_id(service) do
nil ->
nil
service_id ->
suffix = service_id |> String.replace(" ", "_") |> String.upcase()
"AWS_ENDPOINT_URL_" <> suffix
end
end
def input_keys(action, context) do
shapes = context.shapes
input_shape = action.input["target"]
maybe_shape = Enum.filter(shapes, fn {name, _shape} -> input_shape == name end)
case maybe_shape do
[] ->
[]
[{_name, shape}] ->
Enum.reduce(
shape.members,
[],
fn
{name, %{"traits" => traits}}, acc ->
if Map.has_key?(traits, "smithy.api#required") do
[name <> " Required: true" | acc]
else
[name <> " Required: false" | acc]
end
{name, _shape}, acc ->
[name <> " Required: false" | acc]
end
)
|> Enum.reverse()
end
end
def maybe_add_parens(string) do
if String.ends_with?(string, "()") do
string
else
string <> "()"
end
end
end