Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F13142119
vault.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
vault.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# Salt :: tests :: config :: Vault
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Connect to Vault
# License: BSD-2-Clause
# -------------------------------------------------------------
import
yaml
import
json
import
requests
import
sys
def
get_config_path
():
# As long as we deploy primary servers on FreeBSD,
# this path is stable.
return
"/usr/local/etc/salt/master.d/vault.conf"
def
load_config
():
with
open
(
get_config_path
())
as
fd
:
return
yaml
.
safe_load
(
fd
)
def
connect_to_vault
():
config
=
load_config
()
authdata
=
json
.
dumps
(
config
[
"vault"
][
"auth"
])
url
=
config
[
"vault"
][
"url"
]
+
"/v1/auth/approle/login"
r
=
requests
.
post
(
url
,
verify
=
config
[
"vault"
][
"verify"
],
data
=
authdata
)
if
r
.
status_code
!=
200
:
return
False
auth
=
r
.
json
()[
"auth"
]
print
(
"Can connect to Vault:"
)
for
k
in
[
"metadata"
,
"policies"
,
"token_policies"
,
"token_type"
]:
print
(
f
"
\t
{k}: {auth[k]}"
)
return
True
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
run_tests
():
return
connect_to_vault
()
if
__name__
==
"__main__"
:
is_success
=
run_tests
()
sys
.
exit
(
0
if
is_success
else
1
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Nov 21, 16:10 (4 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3155781
Default Alt Text
vault.py (1 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment