mirror of
https://github.com/hoshikawa2/OCI_API_Gateway_Automation2.git
synced 2026-03-03 16:09:36 +00:00
Adaptação: os patterns na especificação não funcionam corretamente com a \ por problemas de escape characters. JSON e regex não vão funcionar corretamente por problemas de conversão entre as bibliotecas. Foi feita uma adaptação para substituir alguns patterns com \ por outras opções.
- `\d`: Corresponde a qualquer dígito decimal; isso é equivalente à classe `[0-9]`. - `\D`: Corresponde a qualquer caractere que não seja um dígito decimal; isso é equivalente à classe `[^0-9]`. - `\w`: Corresponde a qualquer caractere alfanumérico; isso é equivalente à classe `[a-zA-Z0-9_]`. - `\W`: Corresponde a qualquer caractere não-alfanumérico; isso é equivalente à classe `[^a-zA-Z0-9_]`. - `\s`: Corresponde a qualquer caractere de espaço em branco; isso é equivalente à classe `[ \t\n\r\f\v]`. - `\S`: Corresponde a qualquer caractere que não seja um espaço em branco; isso é equivalente à classe `[^ \t\n\r\f\v]`. - `\b`: Corresponde a uma fronteira de palavra, um lugar onde um caractere `\w` é seguido ou precedido por um caractere `\W`. - `\B`: Corresponde a um local onde a fronteira de uma palavra não é encontrada. - `\\`: Corresponde a uma única barra invertida `\`. - `\A`: Corresponde ao início da string. - `\Z`: Corresponde ao fim da string. Como se pode notar, \s, \S, \b, \B, \\, \A e \Z não estão cobertos neste ajuste.
This commit is contained in:
Binary file not shown.
@@ -40,6 +40,47 @@ def beautify_str(str_msg):
|
||||
|
||||
###
|
||||
|
||||
def replace_regex(variavel):
|
||||
variavel = variavel.replace("\\d", "[0-9]")
|
||||
variavel = variavel.replace("\\D", "[^0-9]")
|
||||
variavel = variavel.replace("\\w", "[a-zA-Z0-9_]")
|
||||
variavel = variavel.replace("\\W", "[^a-zA-Z0-9_]")
|
||||
variavel = variavel.replace("/^", "^")
|
||||
variavel = variavel.replace("$/", "$")
|
||||
|
||||
return variavel
|
||||
|
||||
def replace_escape_chars(obj):
|
||||
for k, v in obj.items():
|
||||
if isinstance(v, str):
|
||||
obj[k] = replace_regex(v)
|
||||
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] = replace_regex(v[i])
|
||||
elif isinstance(v[i], dict):
|
||||
v[i] = replace_escape_chars(v[i])
|
||||
return obj
|
||||
|
||||
def remove_property(dictionary, property_name):
|
||||
keys_to_delete = [key for key in dictionary if key == property_name]
|
||||
for key in keys_to_delete:
|
||||
if ("\\s" in dictionary[key] or "\\S" in dictionary[key] or "\\w" in dictionary[key] or "\\W" in dictionary[key]
|
||||
or "\\b" in dictionary[key] or "\\B" in dictionary[key] or "\\A" in dictionary[key] or "\\Z" in dictionary[key]):
|
||||
del dictionary[key]
|
||||
else:
|
||||
dictionary[key] = replace_regex(dictionary[key])
|
||||
for value in dictionary.values():
|
||||
if isinstance(value, dict):
|
||||
remove_property(value, property_name)
|
||||
elif isinstance(value, list):
|
||||
for item in value:
|
||||
if isinstance(item, dict):
|
||||
remove_property(item, property_name)
|
||||
return dictionary
|
||||
|
||||
def handler(ctx, data: io.BytesIO = None):
|
||||
config = oci.config.from_file("config")
|
||||
logging = oci.loggingingestion.LoggingClient(config)
|
||||
@@ -173,12 +214,14 @@ def handler(ctx, data: io.BytesIO = None):
|
||||
apigateway_client = oci.apigateway.ApiGatewayClient(config)
|
||||
api_spec = apigateway_client.get_api_content(contents[1])
|
||||
spec_dict = json.loads(api_spec.data.content)
|
||||
spec_dict = remove_property(spec_dict, "pattern")
|
||||
spec = Spec.from_dict(spec_dict, config=bravado_config)
|
||||
try:
|
||||
schema = spec_dict["definitions"][contents[0]]
|
||||
except:
|
||||
schema = spec_dict["components"]["schemas"][contents[0]]
|
||||
validate_object(spec, schema, body)
|
||||
schema_without_pattern = remove_property(schema, "pattern")
|
||||
validate_object(spec, schema_without_pattern, body)
|
||||
except (Exception) as ex3:
|
||||
error_msg = beautify_str(str(ex3))
|
||||
put_logs_response = logging.put_logs(
|
||||
|
||||
Reference in New Issue
Block a user