mirror of
https://github.com/hoshikawa2/OCI_API_Gateway_Automation2.git
synced 2026-03-06 18:21:01 +00:00
New Release. This version can import JSON or YAML API format (OpenAPI or Swagger)
This commit is contained in:
Binary file not shown.
@@ -6,6 +6,7 @@ import oci
|
|||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
import yaml
|
||||||
|
|
||||||
#### IDCS Routines
|
#### IDCS Routines
|
||||||
#### https://docs.oracle.com/en/learn/apigw-modeldeployment/index.html#introduction
|
#### https://docs.oracle.com/en/learn/apigw-modeldeployment/index.html#introduction
|
||||||
@@ -475,6 +476,23 @@ def process_api_spec(api_id, compartmentId, environment, swagger, functionId, ho
|
|||||||
source="EXAMPLE-source-Value",
|
source="EXAMPLE-source-Value",
|
||||||
type="EXAMPLE-type-Value")]))
|
type="EXAMPLE-type-Value")]))
|
||||||
|
|
||||||
|
def is_json(swagger):
|
||||||
|
try:
|
||||||
|
body = json.loads(swagger)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
yaml_object = yaml.safe_load(swagger) # yaml_object will be a list or a dict
|
||||||
|
s = json.dumps(yaml_object, indent=2)
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def convert_json(swagger):
|
||||||
|
yaml_object = yaml.safe_load(swagger) # yaml_object will be a list or a dict
|
||||||
|
return json.dumps(yaml_object, indent=2)
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
def handler(ctx, data: io.BytesIO = None):
|
def handler(ctx, data: io.BytesIO = None):
|
||||||
@@ -494,13 +512,13 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
body = dict(json.loads(data.getvalue().decode('utf-8')).get("data"))["body"]
|
body = dict(json.loads(data.getvalue().decode('utf-8')).get("data"))["body"]
|
||||||
# body content
|
# body content
|
||||||
swagger = str(body)
|
swagger = str(body)
|
||||||
|
if (is_json(swagger)):
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
|
else:
|
||||||
|
body = json.loads(convert_json(swagger))
|
||||||
|
swagger = convert_json(swagger)
|
||||||
|
|
||||||
# functions context variables
|
environment = "DEV"
|
||||||
# fn config app ociapigw-app oci_region us-ashburn-1
|
|
||||||
# fn config app ociapigw-app environment QA
|
|
||||||
oci_region = app_context['oci_region']
|
|
||||||
environment = app_context['environment']
|
|
||||||
|
|
||||||
# header values
|
# header values
|
||||||
access_token = header["token"]
|
access_token = header["token"]
|
||||||
@@ -547,7 +565,6 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
"active": True,
|
"active": True,
|
||||||
"context": {
|
"context": {
|
||||||
"environment": environment,
|
"environment": environment,
|
||||||
"oci_region": oci_region,
|
|
||||||
"api_id": api_id
|
"api_id": api_id
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ six
|
|||||||
PyJWT
|
PyJWT
|
||||||
py3_lru_cache
|
py3_lru_cache
|
||||||
simplejson
|
simplejson
|
||||||
|
PyYAML
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import io
|
|||||||
from fdk import response
|
from fdk import response
|
||||||
import oci
|
import oci
|
||||||
import requests
|
import requests
|
||||||
|
import yaml
|
||||||
|
|
||||||
#### IDCS Routines
|
#### IDCS Routines
|
||||||
#### https://docs.oracle.com/en/learn/apigw-modeldeployment/index.html#introduction
|
#### https://docs.oracle.com/en/learn/apigw-modeldeployment/index.html#introduction
|
||||||
@@ -123,7 +124,7 @@ def process_api_spec(displayName, compartmentId, environment, swagger):
|
|||||||
except(Exception) as ex:
|
except(Exception) as ex:
|
||||||
jsonData = 'error parsing json payload: ' + str(ex)
|
jsonData = 'error parsing json payload: ' + str(ex)
|
||||||
put_logs_response = logging.put_logs(
|
put_logs_response = logging.put_logs(
|
||||||
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
log_id="ocid1.log.oc1.iad.amaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaan",
|
||||||
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=[
|
||||||
@@ -135,6 +136,22 @@ def process_api_spec(displayName, compartmentId, environment, swagger):
|
|||||||
source="EXAMPLE-source-Value",
|
source="EXAMPLE-source-Value",
|
||||||
type="EXAMPLE-type-Value")]))
|
type="EXAMPLE-type-Value")]))
|
||||||
|
|
||||||
|
def is_json(swagger):
|
||||||
|
try:
|
||||||
|
body = json.loads(swagger)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
try:
|
||||||
|
yaml_object = yaml.safe_load(swagger) # yaml_object will be a list or a dict
|
||||||
|
s = json.dumps(yaml_object, indent=2)
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def convert_json(swagger):
|
||||||
|
yaml_object = yaml.safe_load(swagger) # yaml_object will be a list or a dict
|
||||||
|
return json.dumps(yaml_object, indent=2)
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
def handler(ctx, data: io.BytesIO = None):
|
def handler(ctx, data: io.BytesIO = None):
|
||||||
@@ -154,9 +171,13 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
body = dict(json.loads(data.getvalue().decode('utf-8')).get("data"))["body"]
|
body = dict(json.loads(data.getvalue().decode('utf-8')).get("data"))["body"]
|
||||||
# body content
|
# body content
|
||||||
swagger = str(body)
|
swagger = str(body)
|
||||||
|
if (is_json(swagger)):
|
||||||
body = json.loads(body)
|
body = json.loads(body)
|
||||||
|
else:
|
||||||
|
body = json.loads(convert_json(swagger))
|
||||||
|
swagger = convert_json(swagger)
|
||||||
|
|
||||||
environment = "DEV" #for future development
|
environment = "DEV"
|
||||||
|
|
||||||
# header values
|
# header values
|
||||||
access_token = header["token"]
|
access_token = header["token"]
|
||||||
@@ -174,7 +195,7 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
except(Exception) as ex1:
|
except(Exception) as ex1:
|
||||||
jsonData = 'error parsing json payload: ' + str(ex1)
|
jsonData = 'error parsing json payload: ' + str(ex1)
|
||||||
put_logs_response = logging.put_logs(
|
put_logs_response = logging.put_logs(
|
||||||
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
log_id="ocid1.log.oc1.iad.amaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaan",
|
||||||
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=[
|
||||||
@@ -203,6 +224,20 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
"api_id": json.dumps(api_id)
|
"api_id": json.dumps(api_id)
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
# put_logs_response = logging.put_logs(
|
||||||
|
# log_id="ocid1.log.oc1.iad.amaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaan",
|
||||||
|
# put_logs_details=oci.loggingingestion.models.PutLogsDetails(
|
||||||
|
# specversion="EXAMPLE-specversion-Value",
|
||||||
|
# log_entry_batches=[
|
||||||
|
# oci.loggingingestion.models.LogEntryBatch(
|
||||||
|
# entries=[
|
||||||
|
# oci.loggingingestion.models.LogEntry(
|
||||||
|
# data="request payload: " + json.dumps(header),
|
||||||
|
# id="ocid1.test.oc1..00000001.EXAMPLE-id-Value-1")],
|
||||||
|
# source="EXAMPLE-source-Value",
|
||||||
|
# type="EXAMPLE-type-Value")]))
|
||||||
|
|
||||||
|
|
||||||
return response.Response(
|
return response.Response(
|
||||||
ctx, response_data=rdata,
|
ctx, response_data=rdata,
|
||||||
status_code=200,
|
status_code=200,
|
||||||
@@ -212,7 +247,7 @@ def handler(ctx, data: io.BytesIO = None):
|
|||||||
except(Exception) as ex:
|
except(Exception) as ex:
|
||||||
jsonData = 'error parsing json payload: ' + str(ex)
|
jsonData = 'error parsing json payload: ' + str(ex)
|
||||||
put_logs_response = logging.put_logs(
|
put_logs_response = logging.put_logs(
|
||||||
log_id="ocid1.log.oc1.iad.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
log_id="ocid1.log.oc1.iad.amaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaanamaaaaaan",
|
||||||
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=[
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ six
|
|||||||
PyJWT
|
PyJWT
|
||||||
py3_lru_cache
|
py3_lru_cache
|
||||||
simplejson
|
simplejson
|
||||||
|
PyYAML
|
||||||
|
|||||||
Reference in New Issue
Block a user