Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
ldv_utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LDV
ldv_utils
Commits
d70f8a32
Commit
d70f8a32
authored
2 years ago
by
Nico Vermaas
Browse files
Options
Downloads
Patches
Plain Diff
add optional private key and private key password
parent
411ab9ea
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!9
add optional private key and private key password
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+31
-0
31 additions, 0 deletions
README.md
ldv_migrate/ldv_migrate/connection/retrieve_db_connection.py
+27
-12
27 additions, 12 deletions
ldv_migrate/ldv_migrate/connection/retrieve_db_connection.py
with
58 additions
and
12 deletions
README.md
+
31
−
0
View file @
d70f8a32
...
@@ -96,6 +96,35 @@ pip install -e "git+https://git.astron.nl/ldv/ldv_utils.git#egg=ldvspec-migratio
...
@@ -96,6 +96,35 @@ pip install -e "git+https://git.astron.nl/ldv/ldv_utils.git#egg=ldvspec-migratio
```
```
### Configuration
The database and tunnel configuration are in a local file on the host that can be given as a
`--configuration`
parameter.
The parameter file can contain a link to a private key file, and password.
When those keys are not given, the script will try to read the local SSH_CONFIG file
`~/.ssh/config`
. (Note that this does not work on Windows)
See for more documentation about the sshtunnel mechanism:
https://pypi.org/project/sshtunnel/
The following example shows a local configuration using private key.
```
[postgresql-local]
host=localhost
port=5433
database=ldv-spec-db
user=postgres
password=xxxxx
[postgresql-ldv]
tunnelhost=dop821.astron.nl
tunnelusername=sdco
host=sdc-db.astron.nl
port=5432
database=ldvadmin
user=ldvrbow
password=xxxxx
ssh_pkey = "C:\\Program Files Nico\\putty\\astron_private_key.ppk"
ssh_private_key_password = "xxxxx"
```
### Running
### Running
To test if it works
To test if it works
```
bash
```
bash
...
@@ -132,4 +161,6 @@ Some examples:
...
@@ -132,4 +161,6 @@ Some examples:
ldv_migrate --limit 50000 --max_nbr_dps_to_insert_per_request 10000
ldv_migrate --limit 50000 --max_nbr_dps_to_insert_per_request 10000
- Import only 1000 records at production:
- Import only 1000 records at production:
ldv_migrate --limit 1000 --host prod
ldv_migrate --limit 1000 --host prod
ldv_migrate --limit 1000 --verbose --configuration ~/shared/ldv_migrate.cfg
```
```
This diff is collapsed.
Click to expand it.
ldv_migrate/ldv_migrate/connection/retrieve_db_connection.py
+
27
−
12
View file @
d70f8a32
...
@@ -48,6 +48,22 @@ def open_tunnel(configuration_params):
...
@@ -48,6 +48,22 @@ def open_tunnel(configuration_params):
host
=
configuration_params
.
get
(
'
host
'
,
"
no host given
"
)
host
=
configuration_params
.
get
(
'
host
'
,
"
no host given
"
)
port
=
int
(
configuration_params
.
get
(
'
port
'
,
"
no port given
"
))
port
=
int
(
configuration_params
.
get
(
'
port
'
,
"
no port given
"
))
# check if a private key and password was given
ssh_pkey
=
configuration_params
.
get
(
'
ssh_pkey
'
,
None
)
ssh_private_key_password
=
configuration_params
.
get
(
'
ssh_private_key_password
'
,
None
)
logging
.
info
(
"
Creating ssh tunnel for %s and port %s with tunnel host %s and username %s
"
,
repr
(
host
),
port
,
repr
(
tunnel_host
),
repr
(
tunnel_username
))
if
ssh_pkey
:
ssh_tunnel
=
SSHTunnelForwarder
(
ssh_address_or_host
=
tunnel_host
,
ssh_username
=
tunnel_username
,
remote_bind_address
=
(
host
,
port
),
ssh_pkey
=
ssh_pkey
,
ssh_private_key_password
=
ssh_private_key_password
)
else
:
try
:
try
:
ssh_config_file
=
os
.
path
.
expanduser
(
"
~/.ssh/config
"
)
ssh_config_file
=
os
.
path
.
expanduser
(
"
~/.ssh/config
"
)
except
FileNotFoundError
as
exc
:
except
FileNotFoundError
as
exc
:
...
@@ -55,14 +71,13 @@ def open_tunnel(configuration_params):
...
@@ -55,14 +71,13 @@ def open_tunnel(configuration_params):
"
Ssh config file not found on standard path
'
~/.ssh/config
'
. This is mandatory for opening the ssh tunnel
"
"
Ssh config file not found on standard path
'
~/.ssh/config
'
. This is mandatory for opening the ssh tunnel
"
)
from
exc
)
from
exc
logging
.
info
(
"
Creating ssh tunnel for %s and port %s with tunnel host %s and username %s
"
,
repr
(
host
),
port
,
repr
(
tunnel_host
),
repr
(
tunnel_username
))
ssh_tunnel
=
SSHTunnelForwarder
(
ssh_tunnel
=
SSHTunnelForwarder
(
ssh_address_or_host
=
tunnel_host
,
ssh_address_or_host
=
tunnel_host
,
ssh_username
=
tunnel_username
,
ssh_username
=
tunnel_username
,
ssh_config_file
=
ssh_config_file
,
ssh_config_file
=
ssh_config_file
,
remote_bind_address
=
(
host
,
port
)
remote_bind_address
=
(
host
,
port
)
,
)
)
ssh_tunnel
.
start
()
ssh_tunnel
.
start
()
return
ssh_tunnel
return
ssh_tunnel
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment