132 lines
3.9 KiB
Plaintext
132 lines
3.9 KiB
Plaintext
use ~/bin/nu_scripts/ht.nu
|
|
use ~/bin/nu_scripts/jwt.nu
|
|
use ~/bin/nu_scripts/credm.nu
|
|
|
|
def token-name [] {
|
|
$"($env.XS_SF_ACCOUNT).token"
|
|
}
|
|
|
|
export def request-token [] {
|
|
credm get $env.XS_SF_ACCOUNT
|
|
| select login password
|
|
| rename username password
|
|
| to json
|
|
| ht post (ht with-path $env.XS_SF_URL "/1/rest/accounts/authentication/requesttoken")
|
|
| from json
|
|
}
|
|
|
|
def today [] {
|
|
date now | format date "%Y%m%d"
|
|
}
|
|
|
|
export def request-tenant-key [] {
|
|
let token = (request-token)
|
|
let tenant_id = ($token | get token | jwt parse | get payload.tenantId)
|
|
let url = (ht with-path $env.XS_SF_URL $"/1/rest/security/keyvault/key/($tenant_id)/(today)")
|
|
ht get $url --bearer $token.token
|
|
}
|
|
|
|
def sc-get [path:string] {
|
|
^xh get -A bearer -a $"(provide-access-token)" (ht with-path $env.XS_SF_URL $path) | from json
|
|
}
|
|
|
|
def sc-post [path:string] {
|
|
^xh post -A bearer -a $"(provide-access-token)" (ht with-path $env.XS_SF_URL $path) | from json
|
|
}
|
|
|
|
def sc-put [path:string] {
|
|
^xh put -A bearer -a $"(provide-access-token)" (ht with-path $env.XS_SF_URL $path) | from json
|
|
}
|
|
def sc-delete [path:string] {
|
|
^xh delete -A bearer -a $"(provide-access-token)" (ht with-path $env.XS_SF_URL $path) | from json
|
|
}
|
|
|
|
export def-env update-access-token [] {
|
|
print -e $"Login as (ansi pb)($env.XS_SF_ACCOUNT)(ansi reset)"
|
|
let token_response = (request-token)
|
|
if "ErrorCode" in $token_response {
|
|
print "ERROR"
|
|
let error_msg = $"Could not login into smart cloud as user ($env.XS_SF_ACCOUNT): ($token_response | get Message)"
|
|
error make {
|
|
msg: $error_msg
|
|
}
|
|
}
|
|
$token_response | credm update-token-response (token-name)
|
|
$token_response.token
|
|
}
|
|
|
|
export def provide-access-token [] {
|
|
let token = (credm get (token-name))
|
|
if not "password" in $token {
|
|
update-access-token
|
|
} else {
|
|
$token.password
|
|
}
|
|
}
|
|
|
|
export def list-subsystems [] {
|
|
sc-get "/1/rest/subsystems/management/" | get subsystemInfos
|
|
}
|
|
|
|
export def upload-sub [name:string@xs-subsystem-names, sub_path:string] {
|
|
^xh put --form -A bearer -a $"(provide-access-token)" (ht with-path $env.XS_SF_URL $"/1/rest/subsystems/management/($name)") 'subsystem-meta-data={ "description" : "Eine tolle Beschreibung" }' $"subsystem-data@($sub_path)"
|
|
| from json
|
|
}
|
|
|
|
export def xs-subsystem-names [] {
|
|
[
|
|
"XS-Service-Test",
|
|
"XS-Service-Prod",
|
|
]
|
|
}
|
|
|
|
def xs-matching-db-table-names [] {
|
|
[
|
|
"XS_SETTINGS"
|
|
]
|
|
}
|
|
|
|
|
|
export def start-transaction [
|
|
subsystem:string@xs-subsystem-names,
|
|
table:string@xs-matching-db-table-names,
|
|
columns:list
|
|
--clear
|
|
] {
|
|
{
|
|
subsystem: $subsystem,
|
|
tableMetaData: [{
|
|
tableName: $table,
|
|
clear: $clear,
|
|
columns: $columns
|
|
}]
|
|
} | to json
|
|
| sc-post /1/rest/subsystems/transactions/
|
|
}
|
|
|
|
export def tenant-settings [] {
|
|
let creds = (credm get $env.XS_SF_ACCOUNT)
|
|
{
|
|
"XS_BACKEND_URL": (ht with-path $env.XS_URL "/"),
|
|
"SF_URL": (ht with-path $env.XS_SF_URL "/"),
|
|
"TENANT_USER": $creds.login,
|
|
"TENANT_PASSWORD": $creds.password
|
|
}
|
|
}
|
|
|
|
export def commit-transaction [transaction_id:string] {
|
|
sc-delete $"/1/rest/subsystems/transactions/($transaction_id)/commit"
|
|
}
|
|
|
|
export def settings-db-row-count [name:string@xs-subsystem-names] {
|
|
sc-get $"/1/rest/subsystems/masterdata/count/($name)/XS_SETTINGS/Active"
|
|
}
|
|
|
|
export def update-tenant-settings [name:string@xs-subsystem-names] {
|
|
print -e $"Update settings for tenant ($env.XS_SF_ACCOUNT) and subsystem ($name)"
|
|
let transaction_id = (start-transaction $name XS_SETTINGS ["SETTINGS_KEY", "SETTINGS_VALUE"] --clear | get transactionId)
|
|
print -e $"transaction id: (ansi pb)($transaction_id)(ansi reset)"
|
|
tenant-settings | transpose | rename key value | each { |x| [$x.key,$x.value] } | to json
|
|
| sc-put $"/1/rest/subsystems/transactions/($transaction_id)/XS_SETTINGS"
|
|
commit-transaction $transaction_id
|
|
} |