mirror of
https://github.com/hoshikawa2/OCI_API_Gateway_Automation2.git
synced 2026-03-06 02:10:36 +00:00
Caso de uso para mesmo PATH com vários métodos. Neste caso, um dos métodos não possui validação de schema e os demais possuem. Antes da correção, há validação de schema para todos os métodos deste mesmo PATH. A correção foi feita para separar o deployment do mesmo PATH em linhas diferentes, para que a validação de schema (body_validation_schema) seja feita apenas aonde deve ser.
This commit is contained in:
Binary file not shown.
@@ -181,12 +181,12 @@ def applyAuthApi(compartmentId, displayName, payload, functionId, host, api_gate
|
|||||||
routes = [ ]
|
routes = [ ]
|
||||||
new_routes = [ ]
|
new_routes = [ ]
|
||||||
for item in payload:
|
for item in payload:
|
||||||
methods = json.loads(json.dumps(item["METHOD"].split(" ")))
|
methods = [item["METHOD"]]
|
||||||
path_prefix = item["PATH_PREFIX"]
|
path_prefix = item["PATH_PREFIX"]
|
||||||
callback_url = ("https://" + host + item["PATH_PREFIX"] + "validation-callback" + item["PATH"]).replace("{", "${request.path[").replace("}", "]}")
|
callback_url = ("https://" + host + item["PATH_PREFIX"] + "validation-callback" + item["PATH"]).replace("{", "${request.path[").replace("}", "]}")
|
||||||
if (item["SCHEMA_BODY_VALIDATION"] != ""):
|
if (item["SCHEMA_BODY_VALIDATION"] != ""):
|
||||||
put_logs_response = logging.put_logs(
|
put_logs_response = logging.put_logs(
|
||||||
log_id="ocid1.log.oc1.iad.amaaaaaaamaaaaaaamaaaaaaamaaaaaaamaaaaaaamaaaaaaamaaaaaaamaaaaaa",
|
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||||
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
||||||
specversion="EXAMPLE-specversion-Value",
|
specversion="EXAMPLE-specversion-Value",
|
||||||
log_entry_batches=[
|
log_entry_batches=[
|
||||||
@@ -325,34 +325,6 @@ def applyAuthApi(compartmentId, displayName, payload, functionId, host, api_gate
|
|||||||
|
|
||||||
creeateOrUpdateDeployment(compartmendId=compartmentId, displayName=displayName, validation_deployment_details=validation_deployment_details, create_deployment_details=create_deployment_details, api_gateway_id=api_gateway_id)
|
creeateOrUpdateDeployment(compartmendId=compartmentId, displayName=displayName, validation_deployment_details=validation_deployment_details, create_deployment_details=create_deployment_details, api_gateway_id=api_gateway_id)
|
||||||
|
|
||||||
|
|
||||||
def accMethods(routes, path, status):
|
|
||||||
METHOD = ""
|
|
||||||
for spec in routes:
|
|
||||||
if (find_path(spec["path"]) == path and spec["backend"]["status"] == status):
|
|
||||||
for method in spec["methods"]:
|
|
||||||
if (method not in METHOD):
|
|
||||||
METHOD = (METHOD + " " + method).lstrip().upper()
|
|
||||||
return METHOD
|
|
||||||
|
|
||||||
def accMethods_v2(routes, path, status):
|
|
||||||
METHOD = ""
|
|
||||||
for spec in routes:
|
|
||||||
if (spec["path"] == path and spec["backend"]["status"] == status):
|
|
||||||
for method in spec["methods"]:
|
|
||||||
if (method not in METHOD):
|
|
||||||
METHOD = (METHOD + " " + method).lstrip().upper()
|
|
||||||
return METHOD
|
|
||||||
|
|
||||||
def accMethods_v3(routes, path, status):
|
|
||||||
METHOD = ""
|
|
||||||
for spec in routes:
|
|
||||||
if (spec["path"] == path and spec["backend"]["status"] == status):
|
|
||||||
for method in spec["methods"]:
|
|
||||||
if (method not in METHOD):
|
|
||||||
METHOD = (METHOD + " " + method).lstrip().upper()
|
|
||||||
return METHOD
|
|
||||||
|
|
||||||
def check_endpoint(schemes, endpoint):
|
def check_endpoint(schemes, endpoint):
|
||||||
if (schemes == ""):
|
if (schemes == ""):
|
||||||
if (endpoint.find("http://") == -1 and endpoint.find("https://") == -1):
|
if (endpoint.find("http://") == -1 and endpoint.find("https://") == -1):
|
||||||
@@ -368,31 +340,6 @@ def check_endpoint(schemes, endpoint):
|
|||||||
def key_func(k):
|
def key_func(k):
|
||||||
return k['PATH']
|
return k['PATH']
|
||||||
|
|
||||||
def group_by(payload):
|
|
||||||
config = oci.config.from_file("config")
|
|
||||||
logging = oci.loggingingestion.LoggingClient(config)
|
|
||||||
payload = json.loads(payload)
|
|
||||||
INFO = sorted(payload, key=key_func)
|
|
||||||
result_payload = [ ]
|
|
||||||
for key, value in groupby(INFO, key_func):
|
|
||||||
list_elements = [ ]
|
|
||||||
method_list = ""
|
|
||||||
for element in list(value):
|
|
||||||
list_elements.append(element)
|
|
||||||
for subItem in list_elements:
|
|
||||||
item = json.loads(json.dumps(subItem))
|
|
||||||
if (item["METHOD"] not in method_list):
|
|
||||||
method_list = (method_list + " " + item["METHOD"]).lstrip().upper()
|
|
||||||
API_NAME = item["API_NAME"]
|
|
||||||
TYPE = item["TYPE"]
|
|
||||||
ENVIRONMENT = item["ENVIRONMENT"]
|
|
||||||
PATH_PREFIX = item["PATH_PREFIX"]
|
|
||||||
PATH = item["PATH"]
|
|
||||||
ENDPOINT = item["ENDPOINT"]
|
|
||||||
SCHEMA_BODY_VALIDATION = item["SCHEMA_BODY_VALIDATION"]
|
|
||||||
result_payload.append({"API_NAME": API_NAME, "TYPE": TYPE, "ENVIRONMENT": ENVIRONMENT, "PATH_PREFIX": PATH_PREFIX, "PATH": PATH, "ENDPOINT": ENDPOINT, "METHOD": method_list, "SCHEMA_BODY_VALIDATION": SCHEMA_BODY_VALIDATION})
|
|
||||||
return result_payload
|
|
||||||
|
|
||||||
def verify_path(json_data_list):
|
def verify_path(json_data_list):
|
||||||
list_final = []
|
list_final = []
|
||||||
for item in json_data_list:
|
for item in json_data_list:
|
||||||
@@ -460,102 +407,101 @@ def process_api_spec(api_id, compartmentId, environment, swagger, functionId, ho
|
|||||||
status = spec["backend"]["status"]
|
status = spec["backend"]["status"]
|
||||||
specPath = spec["path"]
|
specPath = spec["path"]
|
||||||
|
|
||||||
if (version == "3"):
|
for method in spec["methods"]:
|
||||||
if (has_path_endpoint(endPointOrigin)):
|
METHOD = method.lstrip().upper()
|
||||||
endPoint = find_base_endpoint(endPointOrigin)
|
|
||||||
specPath = (find_base_pathendpoint(endPointOrigin, specPath)).replace("//", "/")
|
if (version == "3"):
|
||||||
fullEndpoint = (endPoint + specPath + spec["path"]).replace("{", "${request.path[").replace("}", "]}")
|
if (has_path_endpoint(endPointOrigin)):
|
||||||
FULL_PATH = specPath
|
endPoint = find_base_endpoint(endPointOrigin)
|
||||||
|
specPath = (find_base_pathendpoint(endPointOrigin, specPath)).replace("//", "/")
|
||||||
|
fullEndpoint = (endPoint + specPath + spec["path"]).replace("{", "${request.path[").replace("}", "]}")
|
||||||
|
FULL_PATH = specPath
|
||||||
|
ENDPOINT = fullEndpoint
|
||||||
|
PATH = spec["path"]
|
||||||
|
PATH_PREFIX = specPath
|
||||||
|
else:
|
||||||
|
fullEndpoint = (endPoint + find_base_path(specPath) + find_path(specPath)).replace("{", "${request.path[").replace("}", "]}")
|
||||||
|
FULL_PATH = specPath
|
||||||
|
ENDPOINT = fullEndpoint
|
||||||
|
PATH = find_path(specPath)
|
||||||
|
PATH_PREFIX = find_base_path(specPath)
|
||||||
|
else:
|
||||||
|
schemes = ""
|
||||||
|
try:
|
||||||
|
schemes = fullSpec["schemes"][0]
|
||||||
|
except:
|
||||||
|
schemes = "https"
|
||||||
|
|
||||||
|
fullEndpoint = check_endpoint(schemes, (endPoint + removeLastSlash(fullSpec["basePath"]) + spec["path"]).replace("{", "${request.path[").replace("}", "]}"))
|
||||||
|
FULL_PATH = fullSpec["basePath"] + spec["path"]
|
||||||
ENDPOINT = fullEndpoint
|
ENDPOINT = fullEndpoint
|
||||||
PATH = spec["path"]
|
PATH = spec["path"]
|
||||||
PATH_PREFIX = specPath
|
PATH_PREFIX = removeLastSlash(fullSpec["basePath"])
|
||||||
METHOD = accMethods_v3(api_spec["routes"], spec["path"], status)
|
|
||||||
else:
|
|
||||||
fullEndpoint = (endPoint + find_base_path(specPath) + find_path(specPath)).replace("{", "${request.path[").replace("}", "]}")
|
|
||||||
FULL_PATH = specPath
|
|
||||||
ENDPOINT = fullEndpoint
|
|
||||||
PATH = find_path(specPath)
|
|
||||||
PATH_PREFIX = find_base_path(specPath)
|
|
||||||
METHOD = accMethods(api_spec["routes"], find_path(spec["path"]), status)
|
|
||||||
else:
|
|
||||||
schemes = ""
|
|
||||||
try:
|
|
||||||
schemes = fullSpec["schemes"][0]
|
|
||||||
except:
|
|
||||||
schemes = "https"
|
|
||||||
|
|
||||||
fullEndpoint = check_endpoint(schemes, (endPoint + removeLastSlash(fullSpec["basePath"]) + spec["path"]).replace("{", "${request.path[").replace("}", "]}"))
|
OPERATIONID = fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["operationId"]
|
||||||
FULL_PATH = fullSpec["basePath"] + spec["path"]
|
API_NAME = fullSpec["info"]["title"]
|
||||||
ENDPOINT = fullEndpoint
|
if (version == "3"):
|
||||||
PATH = spec["path"]
|
|
||||||
PATH_PREFIX = removeLastSlash(fullSpec["basePath"])
|
|
||||||
METHOD = accMethods_v2(api_spec["routes"], PATH, status)
|
|
||||||
|
|
||||||
OPERATIONID = fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["operationId"]
|
|
||||||
API_NAME = fullSpec["info"]["title"]
|
|
||||||
if (version == "3"):
|
|
||||||
try:
|
|
||||||
try:
|
try:
|
||||||
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"]["schema"]["$ref"]).replace("#/components/schemas/", "")
|
try:
|
||||||
SCHEMA_BODY_VALIDATION = reference + "," + api_id
|
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"]["schema"]["$ref"]).replace("#/components/schemas/", "")
|
||||||
|
SCHEMA_BODY_VALIDATION = reference + "," + api_id
|
||||||
|
except:
|
||||||
|
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"])
|
||||||
|
SCHEMA_BODY_VALIDATION = reference
|
||||||
|
CONTENT_TYPE = "application/json"
|
||||||
except:
|
except:
|
||||||
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"])
|
SCHEMA_BODY_VALIDATION = ""
|
||||||
SCHEMA_BODY_VALIDATION = reference
|
CONTENT_TYPE = ""
|
||||||
CONTENT_TYPE = "application/json"
|
else:
|
||||||
except:
|
|
||||||
SCHEMA_BODY_VALIDATION = ""
|
SCHEMA_BODY_VALIDATION = ""
|
||||||
CONTENT_TYPE = ""
|
CONTENT_TYPE = ""
|
||||||
else:
|
try:
|
||||||
SCHEMA_BODY_VALIDATION = ""
|
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["parameters"][0]["schema"]["$ref"]).replace("#/definitions/", "")
|
||||||
CONTENT_TYPE = ""
|
SCHEMA_BODY_VALIDATION = reference + "," + api_id
|
||||||
try:
|
CONTENT_TYPE = "application/json"
|
||||||
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["parameters"][0]["schema"]["$ref"]).replace("#/definitions/", "")
|
except:
|
||||||
SCHEMA_BODY_VALIDATION = reference + "," + api_id
|
SCHEMA_BODY_VALIDATION = ""
|
||||||
CONTENT_TYPE = "application/json"
|
CONTENT_TYPE = ""
|
||||||
except:
|
TYPE = type
|
||||||
SCHEMA_BODY_VALIDATION = ""
|
ENVIRONMENT = environment
|
||||||
CONTENT_TYPE = ""
|
json_data_list.append({
|
||||||
TYPE = type
|
'API_NAME': API_NAME,
|
||||||
ENVIRONMENT = environment
|
'TYPE': TYPE,
|
||||||
json_data_list.append({
|
'ENVIRONMENT': ENVIRONMENT,
|
||||||
'API_NAME': API_NAME,
|
'METHOD': METHOD,
|
||||||
'TYPE': TYPE,
|
'PATH_PREFIX': PATH_PREFIX,
|
||||||
'ENVIRONMENT': ENVIRONMENT,
|
'PATH': PATH,
|
||||||
'METHOD': METHOD,
|
'ENDPOINT': ENDPOINT,
|
||||||
'PATH_PREFIX': PATH_PREFIX,
|
'SCHEMA_BODY_VALIDATION': SCHEMA_BODY_VALIDATION,
|
||||||
'PATH': PATH,
|
'CONTENT_TYPE': CONTENT_TYPE
|
||||||
'ENDPOINT': ENDPOINT,
|
})
|
||||||
'SCHEMA_BODY_VALIDATION': SCHEMA_BODY_VALIDATION,
|
print(API_NAME, TYPE, ENVIRONMENT, METHOD, PATH_PREFIX, PATH, ENDPOINT, SCHEMA_BODY_VALIDATION, CONTENT_TYPE)
|
||||||
'CONTENT_TYPE': CONTENT_TYPE
|
put_logs_response = logging.put_logs(
|
||||||
})
|
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||||
print(API_NAME, TYPE, ENVIRONMENT, METHOD, PATH_PREFIX, PATH, ENDPOINT, SCHEMA_BODY_VALIDATION, CONTENT_TYPE)
|
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
||||||
put_logs_response = logging.put_logs(
|
specversion="EXAMPLE-specversion-Value",
|
||||||
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
log_entry_batches=[
|
||||||
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
oci.loggingingestion.models.LogEntryBatch(
|
||||||
specversion="EXAMPLE-specversion-Value",
|
entries=[
|
||||||
log_entry_batches=[
|
oci.loggingingestion.models.LogEntry(
|
||||||
oci.loggingingestion.models.LogEntryBatch(
|
data="api deployment: " + json.dumps({
|
||||||
entries=[
|
'API_NAME': API_NAME,
|
||||||
oci.loggingingestion.models.LogEntry(
|
'TYPE': TYPE,
|
||||||
data="api deployment: " + json.dumps({
|
'ENVIRONMENT': ENVIRONMENT,
|
||||||
'API_NAME': API_NAME,
|
'METHOD': METHOD,
|
||||||
'TYPE': TYPE,
|
'PATH_PREFIX': PATH_PREFIX,
|
||||||
'ENVIRONMENT': ENVIRONMENT,
|
'PATH': PATH,
|
||||||
'METHOD': METHOD,
|
'ENDPOINT': ENDPOINT,
|
||||||
'PATH_PREFIX': PATH_PREFIX,
|
'SCHEMA_BODY_VALIDATION': SCHEMA_BODY_VALIDATION,
|
||||||
'PATH': PATH,
|
'CONTENT_TYPE': CONTENT_TYPE
|
||||||
'ENDPOINT': ENDPOINT,
|
}),
|
||||||
'SCHEMA_BODY_VALIDATION': SCHEMA_BODY_VALIDATION,
|
id="ocid1.test.oc1..00000001.EXAMPLE-id-Value")],
|
||||||
'CONTENT_TYPE': CONTENT_TYPE
|
source="EXAMPLE-source-Value",
|
||||||
}),
|
type="EXAMPLE-type-Value")]))
|
||||||
id="ocid1.test.oc1..00000001.EXAMPLE-id-Value")],
|
|
||||||
source="EXAMPLE-source-Value",
|
|
||||||
type="EXAMPLE-type-Value")]))
|
|
||||||
|
|
||||||
|
|
||||||
json_data_list = verify_path(json_data_list)
|
json_data_list = verify_path(json_data_list)
|
||||||
payload = json.dumps(json_data_list)
|
payload = json.dumps(json_data_list)
|
||||||
json_data_list = { each['PATH'] : each for each in json_data_list}.values()
|
|
||||||
put_logs_response = logging.put_logs(
|
put_logs_response = logging.put_logs(
|
||||||
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||||
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
||||||
@@ -564,15 +510,12 @@ def process_api_spec(api_id, compartmentId, environment, swagger, functionId, ho
|
|||||||
oci.loggingingestion.models.LogEntryBatch(
|
oci.loggingingestion.models.LogEntryBatch(
|
||||||
entries=[
|
entries=[
|
||||||
oci.loggingingestion.models.LogEntry(
|
oci.loggingingestion.models.LogEntry(
|
||||||
data="json_data_list: " + str(json_data_list),
|
data="json_data_list: " + payload,
|
||||||
id="ocid1.test.oc1..00000001.EXAMPLE-id-Value")],
|
id="ocid1.test.oc1..00000001.EXAMPLE-id-Value")],
|
||||||
source="EXAMPLE-source-Value",
|
source="EXAMPLE-source-Value",
|
||||||
type="EXAMPLE-type-Value")]))
|
type="EXAMPLE-type-Value")]))
|
||||||
|
|
||||||
# if (version == "2"):
|
payload = json.loads(json.dumps(json_data_list))
|
||||||
# payload = json.loads(json.dumps(group_by(payload)))
|
|
||||||
# json_data_list = { each['PATH'] : each for each in payload}.values()
|
|
||||||
payload = json.loads(json.dumps(group_by(payload)))
|
|
||||||
print(payload)
|
print(payload)
|
||||||
applyAuthApi(compartmentId=compartmentId, displayName=API_NAME, payload=payload, functionId=functionId, host=host, api_gateway_id=api_gateway_id, rate_limit=rate_limit)
|
applyAuthApi(compartmentId=compartmentId, displayName=API_NAME, payload=payload, functionId=functionId, host=host, api_gateway_id=api_gateway_id, rate_limit=rate_limit)
|
||||||
|
|
||||||
@@ -702,4 +645,4 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
ctx,
|
ctx,
|
||||||
status_code=401,
|
status_code=401,
|
||||||
response_data=json.dumps({"active": False, "wwwAuthenticate": jsonData})
|
response_data=json.dumps({"active": False, "wwwAuthenticate": jsonData})
|
||||||
)
|
)
|
||||||
@@ -17,7 +17,7 @@ import datetime
|
|||||||
# config = oci.config.from_file(profile_name='DEFAULT')
|
# config = oci.config.from_file(profile_name='DEFAULT')
|
||||||
#
|
#
|
||||||
# Método: getSpec()
|
# Método: getSpec()
|
||||||
# text_file = open("/Teste 2024-03-15/teste1.yaml", "r")
|
# text_file = open("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-15/qrcode.yaml", "r")
|
||||||
|
|
||||||
def migrate_to_apigw(payload, url, clientID, secretID):
|
def migrate_to_apigw(payload, url, clientID, secretID):
|
||||||
auth = clientID + ":" + secretID
|
auth = clientID + ":" + secretID
|
||||||
@@ -35,7 +35,7 @@ def migrate_to_apigw(payload, url, clientID, secretID):
|
|||||||
|
|
||||||
|
|
||||||
def getSpec(name):
|
def getSpec(name):
|
||||||
text_file = open(name, "r")
|
text_file = open(name, "r", encoding='utf-8')
|
||||||
data = text_file.read()
|
data = text_file.read()
|
||||||
text_file.close()
|
text_file.close()
|
||||||
|
|
||||||
@@ -239,14 +239,28 @@ def is_json(swagger):
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def replace_escape_chars(obj):
|
||||||
|
for k, v in obj.items():
|
||||||
|
if isinstance(v, str):
|
||||||
|
obj[k] = v.replace('\\\\', '\\"')
|
||||||
|
elif isinstance(v, dict):
|
||||||
|
obj[k] = replace_escape_chars(v)
|
||||||
|
elif isinstance(v, list):
|
||||||
|
for i in range(len(v)):
|
||||||
|
if isinstance(v[i], str):
|
||||||
|
v[i] = v[i].replace('\\\\', '\\"')
|
||||||
|
elif isinstance(v[i], dict):
|
||||||
|
v[i] = replace_escape_chars(v[i])
|
||||||
|
return obj
|
||||||
|
|
||||||
def convert_json(swagger):
|
def convert_json(swagger):
|
||||||
yaml_object = yaml.safe_load(swagger) # yaml_object will be a list or a dict
|
yaml_object = yaml.safe_load(swagger) # yaml_object will be a list or a dict
|
||||||
return json.dumps(yaml_object, indent=2, default=DateEncoder)
|
x = json.dumps(yaml_object, ensure_ascii=False, indent=2, default=DateEncoder).encode('utf-8')
|
||||||
|
return x.decode()
|
||||||
|
|
||||||
def process_api_spec():
|
def process_api_spec():
|
||||||
# displayName = "EXEMPLO"
|
# displayName = "EXEMPLO"
|
||||||
compartmentId = "ocid1.compartment.oc1..aaaaaaaaqomaaaaaaaaqomaaaaaaaaqomaaaaaaaaqomaaaaaaaaqomaaaaaaaaqom"
|
compartmentId = "ocid1.compartment.oc1..aaaaaaaaqom2belitvh5ubr342rgzyeycvyg3zt6b4i4owmkzpnpwft37rga"
|
||||||
environment = "QA"
|
environment = "QA"
|
||||||
type = "REST"
|
type = "REST"
|
||||||
rate_limit = "2500,CLIENT_IP"
|
rate_limit = "2500,CLIENT_IP"
|
||||||
@@ -261,7 +275,7 @@ def process_api_spec():
|
|||||||
print("erro")
|
print("erro")
|
||||||
|
|
||||||
|
|
||||||
# Create a default config using DEFAULT profile in default location
|
# Create a default config using DEFAULT profile in default location
|
||||||
# Refer to
|
# Refer to
|
||||||
# https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
|
# https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File
|
||||||
# for more info
|
# for more info
|
||||||
@@ -296,40 +310,43 @@ def process_api_spec():
|
|||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
arquivo = []
|
arquivo = []
|
||||||
arquivo.append("/Teste 2024-03-15/teste1.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Testes 2024-03-11/1.0.0-rc2_rcc-interop-agenda_modificado.json")
|
||||||
arquivo.append("/Testes 2024-03-11/teste2.json")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Testes 2024-03-11/caso1.yaml")
|
||||||
arquivo.append("/Testes 2024-03-11/teste3.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Testes 2024-03-11/caso2.yaml")
|
||||||
arquivo.append("/Testes 2024-03-11/teste4.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-15/caso2024-03-15.yaml")
|
||||||
arquivo.append("/Teste 2024-03-15/teste5.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-15/qrcode.yaml")
|
||||||
arquivo.append("/Teste 2024-03-18/teste6.yaml")
|
#arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-18/1.0.0-rc1_cob 1.yaml")
|
||||||
arquivo.append("/Teste 2024-03-18/teste7.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-18/1.0.0-rc1_cobv.yaml")
|
||||||
arquivo.append("/Teste 2024-03-18/teste8.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-18/1.0.0-rc1_loc.yaml")
|
||||||
arquivo.append("/Teste 2024-03-18/teste9.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-18/1.0.0-rc1_lotecobv.yaml")
|
||||||
arquivo.append("/Teste 2024-03-18/teste10.yaml")
|
#arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-18/1.0.0-rc1_pix.yaml")
|
||||||
arquivo.append("/Teste 2024-03-18/teste11.yaml")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-18/1.0.0-rc1_webhook.yaml")
|
||||||
arquivo.append("/Teste 2024-03-20/teste12.json")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-20/1.0.0-rc8_cprs.json")
|
||||||
arquivo.append("/Teste 2024-03-21/teste13.yaml")
|
#arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-21/1.0.0-rc1_cob 1.yaml")
|
||||||
arquivo.append("/Teste 2024-03-21/teste14.json")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-21/1.0.0-rc2_rcc-interop-agenda.json")
|
||||||
arquivo.append("/Teste 2024-03-22/teste15.json")
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-22/1.0.0-rc8_cprs.json")
|
||||||
arquivo.append("/Teste 2024-03-25/teste16.yaml")
|
#arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-03-25/Banco B3/1.0.0-rc1_cob.yaml")
|
||||||
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-06-03/1.0.0-rc1_cob.yaml")
|
||||||
|
arquivo.append("/Users/cristianohoshikawa/Dropbox/ORACLE/B3/API Gateway/Teste 2024-06-19/1.0.0-rc1_cob.yaml")
|
||||||
display = []
|
display = []
|
||||||
display.append("caso1")
|
display.append("Interoperabilidades-Agenda")
|
||||||
display.append("caso2")
|
display.append("caso-1")
|
||||||
display.append("caso3")
|
display.append("caso-2")
|
||||||
display.append("caso4")
|
display.append("caso2024-03-15")
|
||||||
display.append("caso5")
|
display.append("qrcode")
|
||||||
display.append("caso6")
|
#display.append("cob")
|
||||||
display.append("caso7")
|
display.append("cobv")
|
||||||
display.append("caso8")
|
display.append("loc")
|
||||||
display.append("caso9")
|
display.append("lotecobv")
|
||||||
display.append("caso10")
|
#display.append("pix")
|
||||||
display.append("caso11")
|
display.append("webhook")
|
||||||
display.append("caso12")
|
display.append("cprs")
|
||||||
display.append("caso13")
|
#display.append("cob1")
|
||||||
display.append("caso14")
|
display.append("rcc-interop-agenda")
|
||||||
display.append("caso15")
|
display.append("Rural")
|
||||||
display.append("caso16")
|
#display.append("cob")
|
||||||
|
display.append("pix")
|
||||||
|
display.append("GI - Modulo PIX Cob")
|
||||||
idxArquivo = 0
|
idxArquivo = 0
|
||||||
|
|
||||||
while idxArquivo < len(arquivo):
|
while idxArquivo < len(arquivo):
|
||||||
@@ -341,6 +358,16 @@ def process_api_spec():
|
|||||||
data = getSpec(arquivo[idxArquivo])
|
data = getSpec(arquivo[idxArquivo])
|
||||||
fullSpec = json.loads(data)
|
fullSpec = json.loads(data)
|
||||||
|
|
||||||
|
swagger = str(data)
|
||||||
|
swagger2 = str(data)
|
||||||
|
if (is_json(swagger)):
|
||||||
|
body = json.loads(swagger)
|
||||||
|
else:
|
||||||
|
body = json.loads(convert_json(swagger2))
|
||||||
|
swagger = convert_json(data)
|
||||||
|
|
||||||
|
swagger = swagger
|
||||||
|
|
||||||
displayName = display[idxArquivo]
|
displayName = display[idxArquivo]
|
||||||
|
|
||||||
version = "3"
|
version = "3"
|
||||||
@@ -377,81 +404,86 @@ def process_api_spec():
|
|||||||
status = spec["backend"]["status"]
|
status = spec["backend"]["status"]
|
||||||
specPath = spec["path"]
|
specPath = spec["path"]
|
||||||
|
|
||||||
if (version == "3"):
|
for method in spec["methods"]:
|
||||||
if (has_path_endpoint(endPointOrigin)):
|
METHOD = method.lstrip().upper()
|
||||||
endPoint = find_base_endpoint(endPointOrigin)
|
|
||||||
specPath = (find_base_pathendpoint(endPointOrigin, specPath)).replace("//", "/")
|
if (version == "3"):
|
||||||
fullEndpoint = (endPoint + specPath + spec["path"]).replace("{", "${request.path[").replace("}", "]}")
|
if (has_path_endpoint(endPointOrigin)):
|
||||||
FULL_PATH = specPath
|
endPoint = find_base_endpoint(endPointOrigin)
|
||||||
|
specPath = (find_base_pathendpoint(endPointOrigin, specPath)).replace("//", "/")
|
||||||
|
fullEndpoint = (endPoint + specPath + spec["path"]).replace("{", "${request.path[").replace("}", "]}")
|
||||||
|
FULL_PATH = specPath
|
||||||
|
ENDPOINT = fullEndpoint
|
||||||
|
PATH = spec["path"]
|
||||||
|
PATH_PREFIX = specPath
|
||||||
|
#METHOD = accMethods_v3(api_spec["routes"], spec["path"], status)
|
||||||
|
else:
|
||||||
|
fullEndpoint = (endPoint + find_base_path(specPath) + find_path(specPath)).replace("{", "${request.path[").replace("}", "]}")
|
||||||
|
FULL_PATH = specPath
|
||||||
|
ENDPOINT = fullEndpoint
|
||||||
|
PATH = find_path(specPath)
|
||||||
|
PATH_PREFIX = find_base_path(specPath)
|
||||||
|
#METHOD = accMethods(api_spec["routes"], find_path(spec["path"]), status)
|
||||||
|
else:
|
||||||
|
schemes = ""
|
||||||
|
try:
|
||||||
|
schemes = fullSpec["schemes"][0]
|
||||||
|
except:
|
||||||
|
schemes = "https"
|
||||||
|
|
||||||
|
fullEndpoint = check_endpoint(schemes, (endPoint + removeLastSlash(fullSpec["basePath"]) + spec["path"]).replace("{", "${request.path[").replace("}", "]}"))
|
||||||
|
FULL_PATH = fullSpec["basePath"] + spec["path"]
|
||||||
ENDPOINT = fullEndpoint
|
ENDPOINT = fullEndpoint
|
||||||
PATH = spec["path"]
|
PATH = spec["path"]
|
||||||
PATH_PREFIX = specPath
|
PATH_PREFIX = removeLastSlash(fullSpec["basePath"])
|
||||||
METHOD = accMethods_v3(api_spec["routes"], spec["path"], status)
|
#METHOD = accMethods_v2(api_spec["routes"], PATH, status)
|
||||||
|
|
||||||
|
OPERATIONID = fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["operationId"]
|
||||||
|
API_NAME = fullSpec["info"]["title"]
|
||||||
|
if (version == "3"):
|
||||||
|
try:
|
||||||
|
SCHEMA_BODY_VALIDATION = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"])
|
||||||
|
CONTENT_TYPE = "application/json"
|
||||||
|
except:
|
||||||
|
SCHEMA_BODY_VALIDATION = ""
|
||||||
|
CONTENT_TYPE = ""
|
||||||
else:
|
else:
|
||||||
fullEndpoint = (endPoint + find_base_path(specPath) + find_path(specPath)).replace("{", "${request.path[").replace("}", "]}")
|
|
||||||
FULL_PATH = specPath
|
|
||||||
ENDPOINT = fullEndpoint
|
|
||||||
PATH = find_path(specPath)
|
|
||||||
PATH_PREFIX = find_base_path(specPath)
|
|
||||||
METHOD = accMethods(api_spec["routes"], find_path(spec["path"]), status)
|
|
||||||
else:
|
|
||||||
schemes = ""
|
|
||||||
try:
|
|
||||||
schemes = fullSpec["schemes"][0]
|
|
||||||
except:
|
|
||||||
schemes = "https"
|
|
||||||
|
|
||||||
fullEndpoint = check_endpoint(schemes, (endPoint + removeLastSlash(fullSpec["basePath"]) + spec["path"]).replace("{", "${request.path[").replace("}", "]}"))
|
|
||||||
FULL_PATH = fullSpec["basePath"] + spec["path"]
|
|
||||||
ENDPOINT = fullEndpoint
|
|
||||||
PATH = spec["path"]
|
|
||||||
PATH_PREFIX = removeLastSlash(fullSpec["basePath"])
|
|
||||||
METHOD = accMethods_v2(api_spec["routes"], PATH, status)
|
|
||||||
|
|
||||||
OPERATIONID = fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["operationId"]
|
|
||||||
API_NAME = fullSpec["info"]["title"]
|
|
||||||
if (version == "3"):
|
|
||||||
try:
|
|
||||||
SCHEMA_BODY_VALIDATION = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["requestBody"]["content"]["application/json"])
|
|
||||||
CONTENT_TYPE = "application/json"
|
|
||||||
except:
|
|
||||||
SCHEMA_BODY_VALIDATION = ""
|
SCHEMA_BODY_VALIDATION = ""
|
||||||
CONTENT_TYPE = ""
|
CONTENT_TYPE = ""
|
||||||
else:
|
try:
|
||||||
SCHEMA_BODY_VALIDATION = ""
|
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["parameters"][0]["schema"]["$ref"]).replace("#/definitions/", "")
|
||||||
CONTENT_TYPE = ""
|
SCHEMA_BODY_VALIDATION = reference + "," + api_id
|
||||||
try:
|
CONTENT_TYPE = "application/json"
|
||||||
reference = str(fullSpec["paths"][spec["path"]][str(spec["methods"][0]).lower()]["parameters"][0]["schema"]["$ref"]).replace("#/definitions/", "")
|
except:
|
||||||
SCHEMA_BODY_VALIDATION = reference + "," + api_id
|
SCHEMA_BODY_VALIDATION = ""
|
||||||
CONTENT_TYPE = "application/json"
|
CONTENT_TYPE = ""
|
||||||
except:
|
TYPE = type
|
||||||
SCHEMA_BODY_VALIDATION = ""
|
ENVIRONMENT = environment
|
||||||
CONTENT_TYPE = ""
|
json_data_list.append({
|
||||||
TYPE = type
|
'API_NAME': API_NAME,
|
||||||
ENVIRONMENT = environment
|
'TYPE': TYPE,
|
||||||
json_data_list.append({
|
'ENVIRONMENT': ENVIRONMENT,
|
||||||
'API_NAME': API_NAME,
|
'METHOD': METHOD,
|
||||||
'TYPE': TYPE,
|
'PATH_PREFIX': PATH_PREFIX,
|
||||||
'ENVIRONMENT': ENVIRONMENT,
|
'PATH': PATH,
|
||||||
'METHOD': METHOD,
|
'ENDPOINT': ENDPOINT,
|
||||||
'PATH_PREFIX': PATH_PREFIX,
|
'SCHEMA_BODY_VALIDATION': SCHEMA_BODY_VALIDATION,
|
||||||
'PATH': PATH,
|
'CONTENT_TYPE': CONTENT_TYPE
|
||||||
'ENDPOINT': ENDPOINT,
|
})
|
||||||
'SCHEMA_BODY_VALIDATION': SCHEMA_BODY_VALIDATION,
|
print(API_NAME, TYPE, ENVIRONMENT, METHOD, PATH_PREFIX, PATH, ENDPOINT, SCHEMA_BODY_VALIDATION, CONTENT_TYPE)
|
||||||
'CONTENT_TYPE': CONTENT_TYPE
|
|
||||||
})
|
|
||||||
print(API_NAME, TYPE, ENVIRONMENT, METHOD, PATH_PREFIX, PATH, ENDPOINT, SCHEMA_BODY_VALIDATION, CONTENT_TYPE)
|
|
||||||
|
|
||||||
json_data_list = verify_path(json_data_list)
|
json_data_list = verify_path(json_data_list)
|
||||||
payload = json.dumps(json_data_list)
|
payload = json.dumps(json_data_list)
|
||||||
json_data_list = { each['PATH'] : each for each in json_data_list}.values()
|
#json_data_list = { each['PATH'] : each for each in json_data_list}.values()
|
||||||
|
|
||||||
# if (version == "2"):
|
# if (version == "2"):
|
||||||
# payload = json.loads(json.dumps(group_by(payload)))
|
# payload = json.loads(json.dumps(group_by(payload)))
|
||||||
# #json_data_list = { each['PATH'] : each for each in payload}.values()
|
# #json_data_list = { each['PATH'] : each for each in payload}.values()
|
||||||
payload = json.loads(json.dumps(group_by(payload)))
|
#payload = json.loads(json.dumps(group_by(payload)))
|
||||||
|
payload = json.loads(json.dumps(json_data_list))
|
||||||
print(payload)
|
print(payload)
|
||||||
# migrate_to_apigw(payload, "https://teste.integration.ocp.oraclecloud.com:443/ic/api/integration/v1/flows/rest/MIGRATE_TO_APIGW/1.0/convert", "OIC_SERVICE_USER_BASICAUTH", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
|
# migrate_to_apigw(payload, "https://oic-hoshikawa2-idcci5ks1puo-ia.integration.ocp.oraclecloud.com:443/ic/api/integration/v1/flows/rest/MIGRATE_TO_APIGW/1.0/convert", "OIC_SERVICE_USER_BASICAUTH", "e7ae6069-e471-496e-916d-5dc2ae3edac0")
|
||||||
|
applyAuthApi(compartmentId=compartmentId, displayName=API_NAME, payload=payload, functionId="", host="", api_gateway_id="", rate_limit=rate_limit)
|
||||||
|
|
||||||
c = 0
|
c = 0
|
||||||
idxArquivo = idxArquivo + 1
|
idxArquivo = idxArquivo + 1
|
||||||
@@ -460,6 +492,187 @@ def process_api_spec():
|
|||||||
print(ex)
|
print(ex)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
|
def applyAuthApi(compartmentId, displayName, payload, functionId, host, api_gateway_id, rate_limit):
|
||||||
|
config = oci.config.from_file(profile_name='DEFAULT')
|
||||||
|
logging = oci.loggingingestion.LoggingClient(config)
|
||||||
|
apigateway_client = oci.apigateway.DeploymentClient(config)
|
||||||
|
listGateway = apigateway_client.list_deployments(compartment_id=compartmentId, display_name=displayName, lifecycle_state="ACTIVE")
|
||||||
|
gateway = json.loads(str(listGateway.data))
|
||||||
|
ind = -1
|
||||||
|
c = -1
|
||||||
|
if (len(gateway) > 0):
|
||||||
|
c = 0
|
||||||
|
for item in gateway["items"]:
|
||||||
|
if (item["gateway_id"] == api_gateway_id):
|
||||||
|
ind = c
|
||||||
|
break
|
||||||
|
c = c + 1
|
||||||
|
if (gateway["items"] != [] and c > -1 and ind > -1):
|
||||||
|
gateway_id = gateway["items"][ind]["gateway_id"]
|
||||||
|
deployment_id = gateway["items"][ind]["id"]
|
||||||
|
else:
|
||||||
|
gateway_id = api_gateway_id
|
||||||
|
deployment_id = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
rate_config = rate_limit.split(',')
|
||||||
|
rate_seconds = int(rate_config[0])
|
||||||
|
rate_key = rate_config[1]
|
||||||
|
rate_limiting = oci.apigateway.models.RateLimitingPolicy(
|
||||||
|
rate_in_requests_per_second=rate_seconds,
|
||||||
|
rate_key=rate_key)
|
||||||
|
except:
|
||||||
|
rate_limiting = None
|
||||||
|
|
||||||
|
path_prefix = "/"
|
||||||
|
routes = [ ]
|
||||||
|
new_routes = [ ]
|
||||||
|
for item in payload:
|
||||||
|
methods = [item["METHOD"]]
|
||||||
|
path_prefix = item["PATH_PREFIX"]
|
||||||
|
callback_url = ("https://" + host + item["PATH_PREFIX"] + "validation-callback" + item["PATH"]).replace("{", "${request.path[").replace("}", "]}")
|
||||||
|
if (item["SCHEMA_BODY_VALIDATION"] != ""):
|
||||||
|
put_logs_response = logging.put_logs(
|
||||||
|
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||||
|
put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
||||||
|
specversion="EXAMPLE-specversion-Value",
|
||||||
|
log_entry_batches=[
|
||||||
|
oci.loggingingestion.models.LogEntryBatch(
|
||||||
|
entries=[
|
||||||
|
oci.loggingingestion.models.LogEntry(
|
||||||
|
data="callback_url: " + callback_url,
|
||||||
|
id="ocid1.test.oc1..00000001.EXAMPLE-id-Value")],
|
||||||
|
source="EXAMPLE-source-Value",
|
||||||
|
type="EXAMPLE-type-Value")]))
|
||||||
|
routes.append(
|
||||||
|
oci.apigateway.models.ApiSpecificationRoute(
|
||||||
|
path=item["PATH"],
|
||||||
|
backend=oci.apigateway.models.HTTPBackend(
|
||||||
|
type="HTTP_BACKEND",
|
||||||
|
url=callback_url,
|
||||||
|
is_ssl_verify_disabled=False),
|
||||||
|
methods=methods,
|
||||||
|
request_policies=oci.apigateway.models.ApiSpecificationRouteRequestPolicies(
|
||||||
|
header_transformations=oci.apigateway.models.HeaderTransformationPolicy(
|
||||||
|
set_headers=oci.apigateway.models.SetHeaderPolicy(
|
||||||
|
items=[
|
||||||
|
oci.apigateway.models.SetHeaderPolicyItem(
|
||||||
|
name="body_schema_validation",
|
||||||
|
values=[item["SCHEMA_BODY_VALIDATION"]],
|
||||||
|
if_exists="APPEND")]),
|
||||||
|
)
|
||||||
|
)))
|
||||||
|
new_routes.append(
|
||||||
|
oci.apigateway.models.ApiSpecificationRoute(
|
||||||
|
path=item["PATH"],
|
||||||
|
backend=oci.apigateway.models.HTTPBackend(
|
||||||
|
type="HTTP_BACKEND",
|
||||||
|
url=item["ENDPOINT"],
|
||||||
|
is_ssl_verify_disabled=False),
|
||||||
|
methods=methods,
|
||||||
|
request_policies=oci.apigateway.models.ApiSpecificationRouteRequestPolicies(
|
||||||
|
header_transformations=oci.apigateway.models.HeaderTransformationPolicy(
|
||||||
|
set_headers=oci.apigateway.models.SetHeaderPolicy(
|
||||||
|
items=[
|
||||||
|
oci.apigateway.models.SetHeaderPolicyItem(
|
||||||
|
name="body_schema_validation",
|
||||||
|
values=[item["SCHEMA_BODY_VALIDATION"]],
|
||||||
|
if_exists="APPEND")]),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
))
|
||||||
|
|
||||||
|
else:
|
||||||
|
routes.append(
|
||||||
|
oci.apigateway.models.ApiSpecificationRoute(
|
||||||
|
path=item["PATH"],
|
||||||
|
backend=oci.apigateway.models.HTTPBackend(
|
||||||
|
type="HTTP_BACKEND",
|
||||||
|
url=callback_url,
|
||||||
|
is_ssl_verify_disabled=False),
|
||||||
|
methods=methods))
|
||||||
|
new_routes.append(
|
||||||
|
oci.apigateway.models.ApiSpecificationRoute(
|
||||||
|
path=item["PATH"],
|
||||||
|
backend=oci.apigateway.models.HTTPBackend(
|
||||||
|
type="HTTP_BACKEND",
|
||||||
|
url=item["ENDPOINT"],
|
||||||
|
is_ssl_verify_disabled=False),
|
||||||
|
methods=methods))
|
||||||
|
|
||||||
|
|
||||||
|
if (new_routes != [ ]):
|
||||||
|
validation_deployment_details=oci.apigateway.models.UpdateDeploymentDetails(
|
||||||
|
display_name=displayName + "-validation",
|
||||||
|
specification=oci.apigateway.models.ApiSpecification(
|
||||||
|
request_policies=oci.apigateway.models.ApiSpecificationRequestPolicies(
|
||||||
|
rate_limiting=rate_limiting,
|
||||||
|
authentication=oci.apigateway.models.CustomAuthenticationPolicy(
|
||||||
|
type="CUSTOM_AUTHENTICATION",
|
||||||
|
function_id=functionId,
|
||||||
|
is_anonymous_access_allowed=False,
|
||||||
|
parameters={
|
||||||
|
'token': 'request.headers[token]',
|
||||||
|
'body': 'request.body',
|
||||||
|
'body_schema_validation': 'request.headers[body_schema_validation]',
|
||||||
|
'opc-request-id': 'request.headers[opc-request-id]'},
|
||||||
|
cache_key=["token", "opc-request-id"],
|
||||||
|
validation_failure_policy=oci.apigateway.models.ModifyResponseValidationFailurePolicy(
|
||||||
|
type="MODIFY_RESPONSE",
|
||||||
|
response_code="401",
|
||||||
|
response_message="${request.auth[error]}"
|
||||||
|
)
|
||||||
|
)),
|
||||||
|
routes=new_routes))
|
||||||
|
create_deployment_details=oci.apigateway.models.CreateDeploymentDetails(
|
||||||
|
display_name=displayName + "-validation",
|
||||||
|
compartment_id=compartmentId,
|
||||||
|
gateway_id=gateway_id,
|
||||||
|
path_prefix= path_prefix + "validation-callback",
|
||||||
|
specification=oci.apigateway.models.ApiSpecification(
|
||||||
|
request_policies=oci.apigateway.models.ApiSpecificationRequestPolicies(
|
||||||
|
rate_limiting=rate_limiting,
|
||||||
|
authentication=oci.apigateway.models.CustomAuthenticationPolicy(
|
||||||
|
type="CUSTOM_AUTHENTICATION",
|
||||||
|
function_id=functionId,
|
||||||
|
is_anonymous_access_allowed=False,
|
||||||
|
parameters={
|
||||||
|
'token': 'request.headers[token]',
|
||||||
|
'body': 'request.body',
|
||||||
|
'body_schema_validation': 'request.headers[body_schema_validation]',
|
||||||
|
'opc-request-id': 'request.headers[opc-request-id]'},
|
||||||
|
cache_key=["token", "opc-request-id"],
|
||||||
|
validation_failure_policy=oci.apigateway.models.ModifyResponseValidationFailurePolicy(
|
||||||
|
type="MODIFY_RESPONSE",
|
||||||
|
response_code="401",
|
||||||
|
response_message="${request.auth[error]}"
|
||||||
|
)
|
||||||
|
)),
|
||||||
|
routes=new_routes))
|
||||||
|
#creeateOrUpdateDeployment(compartmendId=compartmentId, displayName=displayName + "-validation", validation_deployment_details=validation_deployment_details, create_deployment_details=create_deployment_details, api_gateway_id=api_gateway_id)
|
||||||
|
|
||||||
|
if (routes != [ ]):
|
||||||
|
# The 1st layer will not authenticate
|
||||||
|
validation_deployment_details=oci.apigateway.models.UpdateDeploymentDetails(
|
||||||
|
display_name=displayName,
|
||||||
|
specification=oci.apigateway.models.ApiSpecification(
|
||||||
|
request_policies=oci.apigateway.models.ApiSpecificationRequestPolicies(
|
||||||
|
rate_limiting=rate_limiting),
|
||||||
|
routes=routes))
|
||||||
|
|
||||||
|
create_deployment_details=oci.apigateway.models.CreateDeploymentDetails(
|
||||||
|
display_name=displayName,
|
||||||
|
compartment_id=compartmentId,
|
||||||
|
gateway_id=gateway_id,
|
||||||
|
path_prefix= path_prefix,
|
||||||
|
specification=oci.apigateway.models.ApiSpecification(
|
||||||
|
request_policies=oci.apigateway.models.ApiSpecificationRequestPolicies(
|
||||||
|
rate_limiting=rate_limiting),
|
||||||
|
routes=routes))
|
||||||
|
|
||||||
|
#creeateOrUpdateDeployment(compartmendId=compartmentId, displayName=displayName, validation_deployment_details=validation_deployment_details, create_deployment_details=create_deployment_details, api_gateway_id=api_gateway_id)
|
||||||
|
|
||||||
# Mudar DisplayName e text_file para poder executar
|
# Mudar DisplayName e text_file para poder executar
|
||||||
process_api_spec()
|
process_api_spec()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user