Skip to content

Commit d4e83e7

Browse files
Add arguments for SSL connections (#72)
1 parent 2ff81f6 commit d4e83e7

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ python3 redisgraph_bulk_loader/bulk_insert.py GRAPHNAME [OPTIONS]
4343
| -p | --port INTEGER | Redis server port (default: 6379) |
4444
| -a | --password TEXT | Redis server password (default: none) |
4545
| -u | --unix-socket-path TEXT | Redis unix socket path (default: none) |
46+
| -k | --ssl-keyfile TEXT | Path to SSL keyfile (default: none) |
47+
| -l | --ssl-certfile TEXT | Path to SSL certfile (default: none) |
48+
| -m | --ssl-ca-certs TEXT | Path to SSL CA certs (default: none) |
4649
| -n | --nodes TEXT | Path to Node CSV file with the filename as the Node Label |
4750
| -N | --nodes-with-label TEXT | Node Label followed by path to Node CSV file |
4851
| -r | --relations TEXT | Path to Relationship CSV file with the filename as the Relationship Type |
4952
| -R | --relations-with-type TEXT | Relationship Type followed by path to relationship CSV file |
5053
| -o | --separator CHAR | Field token separator in CSV files (default: comma) |
5154
| -d | --enforce-schema | Requires each cell to adhere to the schema defined in the CSV header |
52-
| -i | --id-type TEXT | The data type of unique node ID properties (either STRING or INTEGER) |
55+
| -j | --id-type TEXT | The data type of unique node ID properties (either STRING or INTEGER) |
5356
| -s | --skip-invalid-nodes | Skip nodes that reuse previously defined IDs instead of exiting with an error |
5457
| -e | --skip-invalid-edges | Skip edges that use invalid IDs for endpoints instead of exiting with an error |
5558
| -q | --quote INT | The quoting format used in the CSV file. QUOTE_MINIMAL=0,QUOTE_ALL=1,QUOTE_NONNUMERIC=2,QUOTE_NONE=3 |

redisgraph_bulk_loader/bulk_insert.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def process_entities(entities):
5252
@click.option('--password', '-a', default=None, help='Redis server password')
5353
@click.option('--user', '-w', default=None, help='Username for Redis ACL')
5454
@click.option('--unix-socket-path', '-u', default=None, help='Redis server unix socket path')
55+
@click.option('--ssl-keyfile', '-k', default=None, help='SSL keyfile')
56+
@click.option('--ssl-certfile', '-l', default=None, help='SSL certfile')
57+
@click.option('--ssl-ca-certs', '-m', default=None, help='SSL CA certs')
5558
# CSV file paths
5659
@click.option('--nodes', '-n', multiple=True, help='Path to node csv file')
5760
@click.option('--nodes-with-label', '-N', nargs=2, multiple=True, help='Label string followed by path to node csv file')
@@ -60,7 +63,7 @@ def process_entities(entities):
6063
@click.option('--separator', '-o', default=',', help='Field token separator in csv file')
6164
# Schema options
6265
@click.option('--enforce-schema', '-d', default=False, is_flag=True, help='Enforce the schema described in CSV header rows')
63-
@click.option('--id-type', '-i', default='STRING', help='The data type of unique node ID properties (either STRING or INTEGER)')
66+
@click.option('--id-type', '-j', default='STRING', help='The data type of unique node ID properties (either STRING or INTEGER)')
6467
@click.option('--skip-invalid-nodes', '-s', default=False, is_flag=True, help='ignore nodes that use previously defined IDs')
6568
@click.option('--skip-invalid-edges', '-e', default=False, is_flag=True, help='ignore invalid edges, print an error message and continue loading (True), or stop loading after an edge loading failure (False)')
6669
@click.option('--quote', '-q', default=0, help='the quoting format used in the CSV file. QUOTE_MINIMAL=0,QUOTE_ALL=1,QUOTE_NONNUMERIC=2,QUOTE_NONE=3')
@@ -71,7 +74,7 @@ def process_entities(entities):
7174
@click.option('--max-token-size', '-t', default=64, help='max size of each token in megabytes (default 64, max 512)')
7275
@click.option('--index', '-i', multiple=True, help='Label:Propery on which to create an index')
7376
@click.option('--full-text-index', '-f', multiple=True, help='Label:Propery on which to create an full text search index')
74-
def bulk_insert(graph, host, port, password, user, unix_socket_path, nodes, nodes_with_label, relations, relations_with_type, separator, enforce_schema, id_type, skip_invalid_nodes, skip_invalid_edges, escapechar, quote, max_token_count, max_buffer_size, max_token_size, index, full_text_index):
77+
def bulk_insert(graph, host, port, password, user, unix_socket_path, ssl_keyfile, ssl_certfile, ssl_ca_certs, nodes, nodes_with_label, relations, relations_with_type, separator, enforce_schema, id_type, skip_invalid_nodes, skip_invalid_edges, escapechar, quote, max_token_count, max_buffer_size, max_token_size, index, full_text_index):
7578
if sys.version_info.major < 3 or sys.version_info.minor < 6:
7679
raise Exception("Python >= 3.6 is required for the RedisGraph bulk loader.")
7780

@@ -86,12 +89,30 @@ def bulk_insert(graph, host, port, password, user, unix_socket_path, nodes, node
8689
# Initialize configurations with command-line arguments
8790
config = Config(max_token_count, max_buffer_size, max_token_size, enforce_schema, id_type, skip_invalid_nodes, skip_invalid_edges, separator, int(quote), store_node_identifiers, escapechar)
8891

92+
kwargs = {
93+
'host': host,
94+
'port': port,
95+
'username': user,
96+
'password': password
97+
}
98+
99+
if unix_socket_path is not None:
100+
kwargs.update({
101+
'unix_socket_path': unix_socket_path
102+
})
103+
104+
if ssl_keyfile or ssl_certfile or ssl_ca_certs:
105+
kwargs.update({
106+
'ssl': True,
107+
'ssl_keyfile': ssl_keyfile,
108+
'ssl_certfile': ssl_certfile,
109+
'ssl_cert_reqs': redis.ssl.CERT_REQUIRED,
110+
'ssl_ca_certs': ssl_ca_certs
111+
})
112+
89113
# Attempt to connect to Redis server
90114
try:
91-
if unix_socket_path is not None:
92-
client = redis.StrictRedis(unix_socket_path=unix_socket_path, username=user, password=password)
93-
else:
94-
client = redis.StrictRedis(host=host, port=port, username=user, password=password)
115+
client = redis.Redis(**kwargs)
95116
except redis.exceptions.ConnectionError as e:
96117
print("Could not connect to Redis server.")
97118
raise e

0 commit comments

Comments
 (0)