使用SecureGateway将NodeJS应用程序与OracleDB连接

时间:2017-07-11 16:33:21

标签: node.js ibm-cloud tls1.2 secure-gateway

我尝试使用SecureGateway将我的NodeJS应用程序连接到Oracle数据库,但无法正常工作。

我执行了测试,当我运行时

'''
Created on 08-Jul-2017

@author: Pranav
'''
import os
import re
from shutil import move

class MyPatterns:
    brackets = "([\(\[]).*?([\)\]])"
    extra_spaces_pattern = " +"

class MyConstants:
    #dir_path = "D:\Other\Books\Knowledge"
    space = ' '
    underscore = '_'    
    blank = ''

def resolve_filenames(dir_path,filename):
    new_file_name = re.sub(MyPatterns.brackets,MyConstants.blank,filename)
    new_file_name = re.sub(MyPatterns.extra_spaces_pattern,MyConstants.space,new_file_name)
    new_file_name = new_file_name.replace(MyConstants.underscore, MyConstants.space)
    new_file_name = new_file_name.title()
    move(os.path.join(dir_path,filename),os.path.join(dir_path, new_file_name))


base_path = "D:\Other\Books"
directories = os.listdir(base_path)
print('Starting process to resolve file names from base path : {}: '.format(base_path))
for d in directories:
    dir_path = os.path.join(base_path, d)
    print('Resolving files for directory : {} '.format(d))
    for i,fname in enumerate(os.listdir(dir_path)):
        print(i,fname)
        resolve_filenames(dir_path, fname)

为了测试我的联系,我没有结果。所以我认为没有创建我的应用程序和我的网关之间的连接。

当我在DataConnect中运行时,正常工作。

我使用var exec = require('child_process').exec; var sys = require('sys'); function puts(error, stdout, stderr) { sys.puts(stdout) } exec("ping 192.168.10.8", puts); 从我的服务器获取信息。

用于创建隧道的函数是

require('bluemix-secure-gateway')

我的结果是我的本地网。

1 个答案:

答案 0 :(得分:1)

要让您的应用程序与Secure Gateway联系,只需使用目标提供的云主机:端口即可。要接受连接,您需要在可以访问数据库的位置运行Secure Gateway Client。

例如,如果我想连接到在本地计算机上运行的Mongo数据库,我可以创建一个目标,其资源主机名设置为localhost,资源端口设置为27017。创建此目标后,将为其分配云主机:端口(例如,cap-sg-prd-3.integration.ibmcloud.com:23432)。

如果我的应用程序通常使用mongodb://localhost:27017/myproject之类的连接字符串连接到Mongo,我会将其更改为mongodb://cap-sg-prd-3.integration.ibmcloud.com:23432/myproject,以便通过Secure Gateway路由连接。