Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F17410046
edit-acme-dns-accounts.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
edit-acme-dns-accounts.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# Let's encrypt — ACME DNS server accounts editor
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Edit acmedns.json to import credentials
# for a specific subdomain to verify.
# License: BSD-2-Clause
# Source file: roles/core/certificates/files/edit-acme-dns-accounts.py
# -------------------------------------------------------------
#
# <auto-generated>
# This file is managed by our rOPS SaltStack repository.
#
# Changes to this file may cause incorrect behavior
# and will be lost if the state is redeployed.
# </auto-generated>
import
json
import
os
import
sys
def
get_acme_accounts_path
():
try
:
return
os
.
environ
[
"ACME_ACCOUNTS"
]
except
KeyError
:
return
"/usr/local/etc/acmedns.json"
ACME_ACCOUNTS_PATH
=
get_acme_accounts_path
()
class
AcmeAccounts
:
def
__init__
(
self
,
path
):
self
.
path
=
path
self
.
accounts
=
{}
def
read_from_file
(
self
):
with
open
(
self
.
path
)
as
fd
:
self
.
accounts
=
json
.
load
(
fd
)
return
self
def
write_to_file
(
self
):
with
open
(
self
.
path
,
"w"
)
as
fd
:
json
.
dump
(
self
.
accounts
,
fd
)
return
self
def
add
(
self
,
domain
,
account_parameters
):
self
.
accounts
[
domain
]
=
account_parameters
return
self
def
remove
(
self
,
domain
):
try
:
del
self
.
accounts
[
domain
]
return
True
except
KeyError
:
return
False
def
merge_with
(
self
,
other_accounts
:
"AcmeAccounts"
):
self
.
accounts
.
update
(
other_accounts
.
accounts
)
return
self
def
usage
():
print
(
f
"Usage: {sys.argv[0]} <command> [parameters]"
,
file
=
sys
.
stderr
)
exit
(
1
)
def
import_other_file
(
file_to_import
):
if
file_to_import
==
ACME_ACCOUNTS_PATH
:
print
(
f
"You're trying to import {ACME_ACCOUNTS_PATH} to itself"
)
exit
(
2
)
accounts_to_import
=
AcmeAccounts
(
file_to_import
)
.
read_from_file
()
AcmeAccounts
(
ACME_ACCOUNTS_PATH
)
.
read_from_file
()
.
merge_with
(
accounts_to_import
)
.
write_to_file
()
commands
=
{
"import"
:
{
"required_argc"
:
3
,
"command_usage"
:
"import <file>"
,
"callable"
:
import_other_file
,
},
}
if
__name__
==
"__main__"
:
argc
=
len
(
sys
.
argv
)
if
argc
<
2
or
sys
.
argv
[
1
]
in
[
"-h"
,
"--help"
,
"/?"
,
"/help"
]:
usage
()
command
=
sys
.
argv
[
1
]
if
command
not
in
commands
:
print
(
f
"Unknown command: {command}"
,
file
=
sys
.
stderr
)
usage
()
command
=
commands
[
command
]
if
argc
<
command
[
"required_argc"
]:
print
(
f
"Usage: {sys.argv[0]} {command['command_usage']}"
,
file
=
sys
.
stderr
)
exit
(
1
)
# We're good, time to invoke our command
command
[
"callable"
](
*
sys
.
argv
[
2
:])
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Mon, Dec 15, 20:10 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3179613
Default Alt Text
edit-acme-dns-accounts.py (2 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment