Skip to content

Commit a86f4a6

Browse files
python vault and openapi (#17)
* data_pump_dir constant typo fix. * dotnet gitignore * inventory-dotnet init * dotnet gitignore * nodejs vault support * dotnet temp remove * python vault support and openapi
1 parent c294f95 commit a86f4a6

File tree

7 files changed

+62
-26
lines changed

7 files changed

+62
-26
lines changed

grabdish/frontend-helidon/src/main/java/io/helidon/data/examples/FrontEndResource.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,24 @@ public String getMetrics(Command command) {
262262
}
263263
}
264264

265+
@POST
266+
@Consumes(MediaType.APPLICATION_JSON)
267+
@Produces(MediaType.TEXT_PLAIN)
268+
@Traced(operationName = "FrontEnd.openAPI")
269+
@Path("/openAPI")
270+
public String openAPI(Command command) {
271+
String urlString = "http://" + command.serviceName + ".msdataworkshop:8080/" + command.commandName;
272+
System.out.println("FrontEndResource.openAPI url:" + urlString);
273+
try {
274+
String response = makeRequest(urlString);
275+
System.out.println("FrontEndResource.openAPI url:" + urlString + " returnString:" + response);
276+
return response;
277+
} catch (Exception e) {
278+
e.printStackTrace();
279+
return asJSONMessage(e);
280+
}
281+
}
282+
265283
private String asJSONMessage(Object e) {
266284
FrontEndResponse frontEndResponse = new FrontEndResponse();
267285
frontEndResponse.message = e.toString();

grabdish/frontend-helidon/src/main/resources/web/index.html-template

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@
146146
</div>
147147
<!-- lab10 -->
148148
<div slot="lab10">
149+
<oj-button disabled="[[inProgress]]" on-oj-action="[[lab10ShowOpenAPIAction]]">Show OpenAPI/Swagger</oj-button>
150+
<br><br>
149151
<oj-button disabled="[[inProgress]]" on-oj-action="[[lab10ShowMetricsAction]]">Show Metrics</oj-button>
150152
<br><br>
151153
<oj-button disabled="[[inProgress]]" on-oj-action="[[lab10healthliveAction]]">Show Health: Liveness</oj-button>
@@ -274,7 +276,7 @@
274276
this.menuTasks.set('lab7', { label: 'Datasources', title: 'Datasources', description: 'Verify that the Datasources are all working' });
275277
this.menuTasks.set('lab8', { label: 'Setup (and Tear Down) Data and Messaging', title: 'Setup (and Tear Down) Data and Messaging', description: 'This lab sets up data and messaging in the database' });
276278
this.menuTasks.set('lab9', { label: 'Transactional', title: 'Transactional', description: 'JSON and relational data types, AQ transactional event-driven communication, saga, event sourcing, and CQRS' });
277-
this.menuTasks.set('lab10', { label: 'Tracing, Metrics, and Health', title: 'Tracing, Metrics, and Health', description: 'Use Helidon features to provide tracing, metrics, and health checks' });
279+
this.menuTasks.set('lab10', { label: 'OpenAPI, Tracing, Metrics, and Health', title: 'OpenAPI, Tracing, Metrics, and Health', description: 'Use Helidon features to provide OpenAPI, tracing, metrics, and health checks' });
278280

279281
//Drives the navigation list itself
280282
this.tasks = new ArrayDataProvider(Array.from(this.menuTasks.entries()).map(entry => { entry[1].id = entry[0]; return entry[1]; }), { keyAttributes: 'id' });
@@ -632,6 +634,30 @@
632634

633635
// Lab 10. ----------------------------------------------------------- //
634636

637+
this.lab10ShowOpenAPIAction = function (event, vm) {
638+
vm.inProgress(true);
639+
var order = {
640+
serviceName: 'order',
641+
commandName: 'openapi',
642+
orderId: -1,
643+
orderItem: '',
644+
deliverTo: ''
645+
};
646+
var fetchOptions = {
647+
method: 'POST',
648+
headers: { 'Content-Type': 'application/json' },
649+
body: JSON.stringify(order)
650+
};
651+
652+
fetch('/openAPI', fetchOptions).then(fetchResult => {
653+
vm.httpCode(fetchResult.status);
654+
fetchResult.text().then(payload => {
655+
vm.labResult(payload);
656+
vm.inProgress(false);
657+
});
658+
});
659+
};
660+
635661
this.lab10ShowMetricsAction = function (event, vm) {
636662
vm.inProgress(true);
637663
var order = {

grabdish/inventory-nodejs/undeploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
# Copyright (c) 2021 Oracle and/or its affiliates.
3-
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
2+
## Copyright (c) 2021 Oracle and/or its affiliates.
3+
## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
44

55
echo delete inventory-nodejs deployment...
66

grabdish/inventory-python/common/dbmgr.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,17 @@
99
import cx_Oracle
1010
import threading
1111
import time
12-
13-
#for vault
1412
import oci
15-
import sys
16-
from datetime import datetime
17-
from datetime import timedelta
18-
13+
import base64
1914
# Parameters
2015
db_connection_count = int(env.get("DB_CONNECTION_COUNT", "1"))
2116
db_user = env.get('DB_USER').strip()
22-
region_id = env.get('REGION_ID').strip()
17+
region_id = env.get('OCI_REGION').strip()
2318
vault_secret_ocid = env.get('VAULT_SECRET_OCID').strip()
2419
# db_password = env.get('DB_PASSWORD').strip()
2520
db_connect_string = env.get('DB_CONNECT_STRING')
26-
27-
kms_vault_client = oci.key_management.KmsVaultClient()
28-
kms_vault_client_composite = oci.key_management.KmsVaultClientCompositeOperations(
29-
kms_vault_client)
30-
db_password = get_secret(vaults_management_client_composite, region_id, vault_secret_ocid).data
21+
region_id = env.get('OCI_REGION').strip()
22+
vault_secret_ocid = env.get('VAULT_SECRET_OCID').strip()
3123

3224
readyfile = ""
3325
logger = None
@@ -86,6 +78,13 @@ def run():
8678

8779
logger.debug("Create Connection Pool Started")
8880
try:
81+
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
82+
secrets_client = oci.secrets.SecretsClient(config={'region': region_id}, signer=signer)
83+
secret_bundle = secrets_client.get_secret_bundle(secret_id = vault_secret_ocid)
84+
logger.debug(secret_bundle)
85+
base64_bytes = secret_bundle.data.secret_bundle_content.content.encode('ascii')
86+
message_bytes = base64.b64decode(base64_bytes)
87+
db_password = message_bytes.decode('ascii')
8988
pool = cx_Oracle.SessionPool(
9089
db_user,
9190
db_password,

grabdish/inventory-python/inventory/app.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
##
31
## Copyright (c) 2021 Oracle and/or its affiliates.
42
## Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
53
import traceback
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
/*
2-
3-
**
4-
** Copyright (c) 2021 Oracle and/or its affiliates.
5-
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6-
*/
7-
Flask_restful
1+
Flask_restful
82
gunicorn
93
cx_Oracle
104
simplejson
5+
oci
116

grabdish/order-helidon/src/main/java/io/helidon/data/examples/OrderResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public Response placeOrder(
183183
@Path("/showorder")
184184
@GET
185185
@Produces(MediaType.APPLICATION_JSON)
186-
public Response showordernocache(
186+
public Response showorder(
187187
@Parameter(description = "The order ID for the order",
188188
required = true,
189189
example = "1",
@@ -193,7 +193,7 @@ public Response showordernocache(
193193
try {
194194
Order order = orderServiceEventProducer.getOrderViaSODA(atpOrderPdb, orderId);
195195
String returnJSON = JsonUtils.writeValueAsString(order);
196-
System.out.println("OrderResource.showordernocache returnJSON:" + returnJSON);
196+
System.out.println("OrderResource.showorder returnJSON:" + returnJSON);
197197
return Response.ok()
198198
.entity(returnJSON)
199199
.build();

0 commit comments

Comments
 (0)