chore: complete generate-vault-secret

This commit is contained in:
vincent 2024-02-13 20:28:38 +01:00
parent bfb3ec3d34
commit 547ce05466

View File

@ -26,7 +26,7 @@ class Vault:
def create_vault_secret (self,secret: VaultSecret) -> None:
resp=requests.post(
url= f'{self.URL}/v1/secrets/data/{secret.path}',
url= f'{self.URL}v1/secrets/data/{secret.path}',
headers={
'X-Vault-Token': self.token
},
@ -34,16 +34,32 @@ class Vault:
"options": {"cas": 0}
})
)
print(resp.url)
if resp.status_code == 200:
print(f"Create {secret.path} done")
else:
print(resp.status_code)
print(resp.content)
def main() -> None:
secretList=[]
secretList.append(VaultSecret("nomad/ldap",{"admin":""}))
listSecret={
"nomad/ldap":{
"admin":""
},
"nomad/gitea":{
"internal_token":"",
"jwt_secret":"",
"secret_key":""
}
}
token=os.getenv('VAULT_TOKEN',"")
vault_addr=os.getenv('VAULT_ADDR',"")
vault=Vault(vault_addr,token)
for secret in secretList:
for k,v in listSecret.items():
secret=VaultSecret(k,v)
vault.create_vault_secret(secret)
if __name__ == '__main__':