Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
#17: Vault connection through Jenkins Credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
marcionemec-daitan committed Jan 16, 2024
1 parent 5d199ad commit bc5b474
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile_Cron
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pipeline {
}
stage('execute-data-sync') {
steps{
withCredentials([usernamePassword(credentialsId: 'IDTESTE_SPAR', passwordVariable: 'Psw_Test', usernameVariable: 'Usr_teste')]) {
withCredentials([string(credentialsId: 'VltEndPoint', variable: 'vltEndPoint'), string(credentialsId: 'VltToken', variable: 'vltToken'), usernamePassword(credentialsId: 'IDTESTE_SPAR', passwordVariable: 'Psw_Test', usernameVariable: 'Usr_teste')]) {
bat '''
source ve/bin/activate
python -m pip install -r ./requirements.txt --cache-dir ./data
Expand Down
19 changes: 16 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import module.data_synchronization as data_sync
from logging import config as logging_config
import os
import os, requests, json

def do_tests_in_jenkins():
print("Starting tests")
print("Starting Jenkins Tests")

# Testing Secrets variable from Jenkins Credentials Plugin
print(os.environ['Usr_teste'] + " " + os.environ['Psw_Test'] )
Expand All @@ -17,11 +17,24 @@ def do_tests_in_jenkins():
print("Password credential accepted")
else:
print("Password credential incorrect")

def do_tests_in_vault():
print("Starting Vault Tests")
vault_token = os.environ['VltToken'] #From Jenkins Credentials
vault_url = os.environ['VltEndPoint'] #From Jenkins Credentials
headers = {'X-Vault-Token': vault_token}
res = requests.get(vault_url, headers=headers)
print(res.text)
j = json.loads(res.text)
print(j)



def main() -> None:
logging_config.fileConfig(os.path.join(os.path.dirname(__file__), "logging.ini"),
disable_existing_loggers=False)
data_sync.data_sync()
#data_sync.data_sync()
do_tests_in_vault()

if __name__ == '__main__':
main()

0 comments on commit bc5b474

Please sign in to comment.