Skip to content

Commit 65dbe3b

Browse files
authored
Merge pull request #12 from mt7479/argparse2
add the ability to specify a different config file
2 parents 63fa34a + 0a70662 commit 65dbe3b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This script can run on any machine running Python 3 that has network access to y
77

88
# Usage
99

10-
There are no command-line arguments to deploy-freenas.py; the relevant configuration takes place in the `deploy_config` file. You can create this file either by copying `depoy_config.example` from this repository, or directly using your preferred text editor. Its format is as follows:
10+
The relevant configuration takes place in the `deploy_config` file. You can create this file either by copying `depoy_config.example` from this repository, or directly using your preferred text editor. Its format is as follows:
1111

1212
```
1313
[deploy]
@@ -24,3 +24,9 @@ port = 443
2424
Everything but the password is optional, and the defaults are documented in `depoy_config.example`.
2525

2626
Once you've prepared `deploy_config`, you can run `deploy_freenas.py`. The intended use is that it would be called by your ACME client after issuing a certificate. With acme.sh, for example, you'd add `--deploy-hook "/path/to/deploy_freenas.py"` to your command.
27+
28+
There is an optional paramter, `-c` or `--config`, that lets you specify the path to your configuration file. By default the script will try to use `deploy_config` in the script working directoy:
29+
30+
```
31+
/path/to/deploy_freenas.py --config /somewhere/else/deploy_config
32+
```

deploy_freenas.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
Source: https://github.com/danb35/deploy-freenas
1616
"""
1717

18+
import argparse
19+
import os
1820
import sys
1921
import json
2022
import requests
@@ -25,9 +27,18 @@
2527
from urllib3.exceptions import InsecureRequestWarning
2628
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
2729

28-
config = configparser.ConfigParser()
29-
config.read('deploy_config')
30-
deploy = config['deploy']
30+
parser = argparse.ArgumentParser(description='Import and activate a SSL/TLS certificate into FreeNAS.')
31+
parser.add_argument('-c', '--config', default=(os.path.join(os.path.dirname(os.path.realpath(__file__)),
32+
'deploy_config')), help='Path to config file, defaults to deploy_config.')
33+
args = parser.parse_args()
34+
35+
if os.path.isfile(args.config):
36+
config = configparser.ConfigParser()
37+
config.read(args.config)
38+
deploy = config['deploy']
39+
else:
40+
print("Config file", args.config, "does not exist!")
41+
exit(1)
3142

3243
USER = "root"
3344
PASSWORD = deploy.get('password')

0 commit comments

Comments
 (0)