-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathapimAPI.bicep
206 lines (186 loc) · 5.28 KB
/
apimAPI.bicep
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
param apimName string
param currentResourceGroup string
param backendApiName string
param apiName string
param originUrl string
var functionAppKeyName = '${backendApiName}-key'
resource backendApiApp 'Microsoft.Web/sites@2021-01-15' existing = {
name: backendApiName
scope: resourceGroup(currentResourceGroup)
}
resource functionKey 'Microsoft.Web/sites/functions/keys@2021-01-15' existing = {
name: '${backendApiName}/GetTodoItems/default'
scope: resourceGroup(currentResourceGroup)
}
resource apim 'Microsoft.ApiManagement/service@2021-01-01-preview' existing = {
name: apimName
}
resource namedValues 'Microsoft.ApiManagement/service/namedValues@2021-01-01-preview' = {
parent: apim
name: functionAppKeyName
properties: {
displayName: functionAppKeyName
value: listKeys('${backendApiApp.id}/host/default','2019-08-01').functionKeys.default
}
}
resource backendApi 'Microsoft.ApiManagement/service/backends@2021-01-01-preview' = {
parent: apim
name: backendApiName
properties: {
description: backendApiName
resourceId: 'https://management.azure.com${backendApiApp.id}'
credentials: {
header:{
'x-functions-key': [
'{{${namedValues.properties.displayName}}}'
]
}
}
url: 'https://${backendApiApp.properties.hostNames[0]}/api'
protocol: 'http'
}
}
resource api 'Microsoft.ApiManagement/service/apis@2021-01-01-preview' = {
parent: apim
name: apiName
properties: {
path: apiName
displayName: apiName
isCurrent: true
subscriptionRequired: false
protocols: [
'https'
]
}
}
resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-01-01-preview' = {
parent: api
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/cos-policy.xml'),'__ORIGIN__',originUrl)
}
}
resource opGetTodos 'Microsoft.ApiManagement/service/apis/operations@2021-01-01-preview' = {
name: 'getTodoList'
parent: api
properties: {
displayName: 'Get Todo List'
method: 'GET'
urlTemplate: '/todos'
}
}
resource opGetTodosPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2021-01-01-preview' = {
parent: opGetTodos
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/api-policy.xml'),'__BACKEND-ID__',backendApi.name)
}
}
resource opGetTodosById 'Microsoft.ApiManagement/service/apis/operations@2021-01-01-preview' = {
name: 'getTodoItem'
parent: api
properties: {
displayName: 'Get Todo Item'
method: 'GET'
urlTemplate: '/todos/{id}'
templateParameters: [
{
name: 'id'
required: true
type: 'String'
}
]
}
}
resource opGetTodosByIdPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2021-01-01-preview' = {
parent: opGetTodosById
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/api-policy.xml'),'__BACKEND-ID__',backendApi.name)
}
}
resource opPostTodoItem 'Microsoft.ApiManagement/service/apis/operations@2021-01-01-preview' = {
name: 'postTodoItem'
parent: api
properties: {
displayName: 'Create Todo Item'
method: 'POST'
urlTemplate: '/todos'
}
}
resource opPostTodoItemPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2021-01-01-preview' = {
parent: opPostTodoItem
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/api-policy.xml'),'__BACKEND-ID__',backendApi.name)
}
}
resource opPutTodosById 'Microsoft.ApiManagement/service/apis/operations@2021-01-01-preview' = {
name: 'putTodoItem'
parent: api
properties: {
displayName: 'Update Todo Item'
method: 'PUT'
urlTemplate: '/todos/{id}'
templateParameters: [
{
name: 'id'
required: true
type: 'String'
}
]
}
}
resource opPutTodosByIdPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2021-01-01-preview' = {
parent: opPutTodosById
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/api-policy.xml'),'__BACKEND-ID__',backendApi.name)
}
}
resource opDeleteTodosById 'Microsoft.ApiManagement/service/apis/operations@2021-01-01-preview' = {
name: 'deleteTodoItem'
parent: api
properties: {
displayName: 'Delete Todo Item'
method: 'DELETE'
urlTemplate: '/todos/{id}'
templateParameters: [
{
name: 'id'
required: true
type: 'String'
}
]
}
}
resource opDeleteTodosByIdPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2021-01-01-preview' = {
parent: opDeleteTodosById
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/api-policy.xml'),'__BACKEND-ID__',backendApi.name)
}
}
resource opHealthCheck 'Microsoft.ApiManagement/service/apis/operations@2021-01-01-preview' = {
name: 'HealthCheck'
parent: api
properties: {
displayName: 'Health Probe'
method: 'HEAD'
urlTemplate: '/todos'
}
}
resource opHealthCheckPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2021-01-01-preview' = {
parent: opHealthCheck
name: 'policy'
properties: {
format: 'rawxml'
value: replace(loadTextContent('../content/api-policy.xml'),'__BACKEND-ID__',backendApi.name)
}
}