-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
134 lines (102 loc) · 3.46 KB
/
client.lua
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
local json = require('./runtime/json')
local http = require('./runtime/http')
local sigv4 = require('./runtime/sigv4')
local Client = {}
local function _do(client, input, target)
local req = http.Request.New()
local endpoint = 'https://sqs.'..client._config.Region..'.amazonaws.com'
req.URL = endpoint
req.Host = 'sqs.'..client._config.Region..'.amazonaws.com'
req.Method = 'POST'
req.Header:Set("Content-Type", "application/x-amz-json-1.0")
req.Header:Set("X-Amz-Target", target)
-- https://github.com/rxi/json.lua/issues/23
-- empty tables encode as [] which awsJson will not accept, so do it ourselves instead
if #input == 0 then
req.Body = '{}'
else
req.Body = json.encode(input)
end
sigv4.Sign(req, client._config.Credentials, "sqs", client._config.Region)
local resp = client._config.HTTPClient:Do(req)
return json.decode(resp.Body), nil
end
function Client.New(config)
return setmetatable({
_config = {
Region = config.Region,
Credentials = config.Credentials,
HTTPClient = config.HTTPClient,
},
}, { __index = Client })
end
function Client:AddPermission(input)
return _do(self, input, "AmazonSQS.AddPermission")
end
function Client:CancelMessageMoveTask(input)
return _do(self, input, "AmazonSQS.CancelMessageMoveTask")
end
function Client:ChangeMessageVisibility(input)
return _do(self, input, "AmazonSQS.ChangeMessageVisibility")
end
function Client:ChangeMessageVisibilityBatch(input)
return _do(self, input, "AmazonSQS.ChangeMessageVisibilityBatch")
end
function Client:CreateQueue(input)
return _do(self, input, "AmazonSQS.CreateQueue")
end
function Client:DeleteMessage(input)
return _do(self, input, "AmazonSQS.DeleteMessage")
end
function Client:DeleteMessageBatch(input)
return _do(self, input, "AmazonSQS.DeleteMessageBatch")
end
function Client:DeleteQueue(input)
return _do(self, input, "AmazonSQS.DeleteQueue")
end
function Client:GetQueueAttributes(input)
return _do(self, input, "AmazonSQS.GetQueueAttributes")
end
function Client:GetQueueUrl(input)
return _do(self, input, "AmazonSQS.GetQueueUrl")
end
function Client:ListDeadLetterSourceQueues(input)
return _do(self, input, "AmazonSQS.ListDeadLetterSourceQueues")
end
function Client:ListMessageMoveTasks(input)
return _do(self, input, "AmazonSQS.ListMessageMoveTasks")
end
function Client:ListQueues(input)
return _do(self, input, "AmazonSQS.ListQueues")
end
function Client:ListQueueTags(input)
return _do(self, input, "AmazonSQS.ListQueueTags")
end
function Client:PurgeQueue(input)
return _do(self, input, "AmazonSQS.PurgeQueue")
end
function Client:ReceiveMessage(input)
return _do(self, input, "AmazonSQS.ReceiveMessage")
end
function Client:RemovePermission(input)
return _do(self, input, "AmazonSQS.RemovePermission")
end
function Client:SendMessage(input)
return _do(self, input, "AmazonSQS.SendMessage")
end
function Client:SendMessageBatch(input)
return _do(self, input, "AmazonSQS.SendMessageBatch")
end
function Client:SetQueueAttributes(input)
return _do(self, input, "AmazonSQS.SetQueueAttributes")
end
function Client:StartMessageMoveTask(input)
return _do(self, input, "AmazonSQS.StartMessageMoveTask")
end
function Client:TagQueue(input)
return _do(self, input, "AmazonSQS.TagQueue")
end
function Client:UntagQueue(input)
return _do(self, input, "AmazonSQS.UntagQueue")
end
return Client