Skip to content

Commit 2312049

Browse files
Bugfixes (#9)
* OpenAPI integration work in progress * API Gateway updates * API Gateway support - beta release * README updated * README updated * README updated * README updated * README updated * README updated * Declaration schema updated, Developer portal alpha release * Postman collection updated * Devportal alpha release commit * Devportal alpha release commit * Added Developer Portal support * README updated * README updated * README updated * README updated * README updated * README updated * README updated * README updated * config.toml updated * Bugfixes * Bugfixes
1 parent 9afa07f commit 2312049

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ Configuration can be customized mounting `config.toml` as a volume `nginx-declar
183183

184184
When NGINX Declarative API is running, REST API documentation can be accessed at:
185185

186-
- Documentation and testing: http://<NGINX_DECLARATIVE_API_ADDRESS>:5000/docs
187-
- Redoc documentation: http://<NGINX_DECLARATIVE_API_ADDRESS>:5000/redoc
188-
- OpenAPI specification: http://<NGINX_DECLARATIVE_API_ADDRESS>:5000/openapi.json
186+
- Documentation and testing: `http://<NGINX_DECLARATIVE_API_ADDRESS>:5000/docs`
187+
- Redoc documentation: `http://<NGINX_DECLARATIVE_API_ADDRESS>:5000/redoc`
188+
- OpenAPI specification: `http://<NGINX_DECLARATIVE_API_ADDRESS>:5000/openapi.json`

contrib/devportal/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ To build:
66

77
docker build --no-cache -t <YOUR_TARGET_IMAGE_NAME> .
88

9-
To run the pre-build image:
9+
To run the pre-built image:
1010

1111
docker run --rm -d -p 5001:5000 --name devportal fiorucci/nginx-declarative-api-devportal
1212

etc/config.toml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ port = 5000
2424

2525
# Redis backend for CI/CD automation
2626
[redis]
27-
host = "127.0.0.1"
27+
host = "redis"
2828
port = 6379
2929

3030
# Devportal helper
3131
[devportal]
3232
host = "devportal"
33-
port = 5000
33+
port = 5001
3434
uri = "/v1/devportal"
3535

3636
# Staged configuration for NGINX Management Suite
@@ -42,15 +42,13 @@ devportal_dir = '/etc/nginx/devportal'
4242
# Time to wait to get status after committing a staged config
4343
staged_config_publish_waittime = 2
4444

45-
# API v0 & V1
45+
# NGINX App Protect support
4646
nap_policies_dir = '/etc/nginx/waf/policies'
4747
nap_logformats_dir = '/etc/nginx/waf/logformats'
4848
nap_logformats_template = "logformat.tmpl"
49-
50-
# API v2 - support for v2 Policy Compiler
5149
nap_policies_dir_pum = '/etc/nms'
5250
nap_logformats_dir_pum = '/etc/nms'
5351

54-
# Staged configuration filenames
52+
# NGINX Instance Manager staged configuration filenames
5553
staged_config_http_filename = 'conf.d/services.conf'
5654
staged_config_stream_filename = 'stream-conf.d/services.conf'

src/Contrib/DevPortal.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414

1515
def buildDevPortal(openapischema):
16-
response = requests.post(f"http://{NcgConfig.config['devportal']['host']}:"
17-
f"{NcgConfig.config['devportal']['port']}{NcgConfig.config['devportal']['uri']}",
18-
headers={'Content-Type': 'application/json'}, data=openapischema)
16+
try:
17+
response = requests.post(f"http://{NcgConfig.config['devportal']['host']}:"
18+
f"{NcgConfig.config['devportal']['port']}{NcgConfig.config['devportal']['uri']}",
19+
headers={'Content-Type': 'application/json'}, data=openapischema)
20+
except Exception as e:
21+
return 400, ""
1922

2023
return response.status_code, json.loads(response.text)
2124

@@ -32,6 +35,9 @@ def createDevPortal(locationDeclaration: dict):
3235
apiSchemaString = Contrib.MiscUtils.yaml_to_json(apiSchemaString)
3336

3437
status, devportalJSON = buildDevPortal(openapischema=apiSchemaString)
35-
devportalHTML = base64.b64encode(bytes(devportalJSON['devportal'], 'utf-8')).decode('utf-8')
38+
if status == 200:
39+
devportalHTML = base64.b64encode(bytes(devportalJSON['devportal'], 'utf-8')).decode('utf-8')
40+
else:
41+
devportalHTML = ""
3642

37-
return 200, devportalHTML
43+
return status, devportalHTML

src/V3_CreateConfig.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ def createconfig(declaration: ConfigDeclaration, apiversion: str, runfromautosyn
152152
status, devPortalHTML = (
153153
Contrib.DevPortal.createDevPortal(locationDeclaration=loc))
154154

155+
if status != 200:
156+
return {"status_code": 400,
157+
"message": {"status_code": status, "message":
158+
{"code": status, "content": f"Developer Portal creation failed for {loc['apigateway']['openapi_schema']}"}}}
159+
155160
### Add optional API Developer portal HTML files
156161
# devPortalHTML
157162
newAuxFile = {'contents': devPortalHTML, 'name': NcgConfig.config['nms']['devportal_dir'] +
@@ -443,8 +448,13 @@ def createconfig(declaration: ConfigDeclaration, apiversion: str, runfromautosyn
443448
print(f'Configuration [{configUid}] changed, publishing to NMS')
444449

445450
# Retrieve instance group uid
446-
ig = requests.get(url=f'{nmsUrl}/api/platform/v1/instance-groups', auth=(nmsUsername, nmsPassword),
447-
verify=False)
451+
try:
452+
ig = requests.get(url=f'{nmsUrl}/api/platform/v1/instance-groups', auth=(nmsUsername, nmsPassword),
453+
verify=False)
454+
except Exception as e:
455+
return {"status_code": 400,
456+
"message": {"status_code": 400,
457+
"message": {"code": 400, "content": f"Can't connect to {nmsUrl}"}}}
448458

449459
if ig.status_code != 200:
450460
try:

src/V3_NginxConfigDeclaration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111

1212
class OutputConfigMap(BaseModel, extra=Extra.forbid):
13-
name: str = ""
13+
name: str = "nginx-config"
1414
namespace: Optional[str] = ""
15-
filename: str = ""
15+
filename: str = "nginx-config.conf"
1616

1717

1818
class OutputHttp(BaseModel, extra=Extra.forbid):

0 commit comments

Comments
 (0)