Last active
March 12, 2024 13:10
-
-
Save yunarta/0ce4cd8ab1dd1adb2cd1c7db5f9b551e to your computer and use it in GitHub Desktop.
python code for using nexus as terraform state backend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_state(method, path, body): | |
session = requests.sessions.Session() | |
session.auth = ('jenkins', 'jenkins') | |
if method == 'GET': | |
response = session.get(url=f"http://nxrm.funf/repository/storage-terraform-states{path}") | |
if response.status_code == 404: | |
return { | |
'statusCode': 200, | |
'body': { | |
'version': 1 | |
} | |
} | |
else: | |
return { | |
'statusCode': 200, | |
'body': response.json() | |
} | |
elif method == 'POST': | |
content_buffer = io.BytesIO() | |
content_buffer.write(body) | |
content_buffer.seek(0) | |
response = session.put(url=f"http://nxrm.funf/repository/storage-terraform-states{path}", data=content_buffer) | |
print(response.status_code, file=stderr) | |
print(response.text, file=stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment