Dynamic Query to Update Vault
  • 09 Aug 2024
  • 1 Minute to read
  • PDF

Dynamic Query to Update Vault

  • PDF

Article summary

Use the below SQL statements for "Dynamic Query to Update Vault". 

DECLARE @Provider NVARCHAR(255),@URL NVARCHAR(255), @sql NVARCHAR(max),@Token NVARCHAR(255),@vaultname NVARCHAR(255),

@DBname NVARCHAR(255),@servername NVARCHAR(255),@User NVARCHAR(255),@PW NVARCHAR(255)

Change the below values as per your instance.

  • SET @Provider = 'hashicorp'
    If needed replace 'hashicorp' with the provider name.  

  • SET @URL = 'http://10.63.0.5:8200' 
    If needed replace 'http://10.63.0.5:8200' with the new URL.

  • SET @Token = 'hvs.Xg2d2iQpRVMnmICUfnkthexq'
    If needed replace 'hvs.Xg2d2iQpRVMnmICUfnkthexq' with the new token name.

  • SET @vaultname = 'stgsymphonyindustrial'
    If needed replace 'stgsymphonyindustrial' with the new vault name.

  • SET @DBname = 'Stgsymphonyindustrial'  
    If needed replace 'Stgsymphonyindustrial' with the new DB name.

  • SET @servername = 'apexwepocsql01'
    If needed replace 'apexwepocsql01' with the new server's name or IP address.

  • SET @User = 'db_demo' 
    If needed replace 'db_demo' with the new login username.

  • SET @PW = 'Welcome@123' 
    If needed replace 'Welcome@123' with the new password.  

  • SET @Provider = ''

set @sql =

    '

 update plt_app_setting set setting_value = ''{"Provider":"[#Provider#]","Hashicorp":{"VaultEndpointUri":"[#URL#]","Token":"[#Token#]","VaultEngine":"kv","VaultName":"[#Vaultname#]","AppRoleId":"","AppRoleSecret":"","BootstrapToken":"","AdminUserName":"","AdminUserPassword":"","ByPassVault":""},"Azure":{"TenantId":"","VaultUri":"","ClientId":"","ClientSecret":""},"Summit":{"RootKey":"","Database":"","ConnectionString":"Data Source=[#servername#];initial Catalog=[#DBName#];User Id=[#user#];Password=[#PW#]"}}''

where setting_key = ''Vault'';

update plt_vault set secret_value = ''Data Source=[#servername#];initial Catalog=[#DBName#];User Id=[#user#];Password=[#PW#]''

where id =2;

';

    SET @sql = Replace(@sql,'[#username#]',@user)

    SET @sql = Replace(@sql,'[#Provider#]',@Provider)

    SET @sql = Replace(@sql,'[#URL#]',@URL)

    SET @sql = Replace(@sql,'[#Token#]',@Token)

    SET @sql = Replace(@sql,'[#Vaultname#]',@vaultname)

    SET @sql = Replace(@sql,'[#servername#]',@servername)

    SET @sql = Replace(@sql,'[#DBName#]',@DBname)

    SET @sql = Replace(@sql,'[#user#]',@User)

    SET @sql = Replace(@sql,'[#PW#]',@PW)

    PRINT (@sql);

    EXEC (@sql);




    


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.