Xbase++ Requires Chilkat v11.5.0+
Xbase++
Example: Secrets.SecretSpecToJson method
Demonstrates theSecretSpecToJson method. This method converts a secret specification string to the JSON required to create or lookup the secret.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oSecrets
LOCAL oJson
LOCAL cSspec
nSuccess := 0
oSecrets := CreateObject("Chilkat.Secrets")
oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
// A secret name can include up to 4 components:
// [appName] / service / [domain] / username
// This example will demonstrate secret specification strings
// for each possible combination.
// ------------------------------------------------------
// 1: service + username
cSspec := "!!imap|john@example.com"
oSecrets:SecretSpecToJson(cSspec, oJson)
? oJson:Emit()
// Result:
// {
// "service": "imap",
// "username": "john@example.com"
// }
// ------------------------------------------------------
// 2: appName + service + username
cSspec := "!!myApp|imap|john@example.com"
oSecrets:SecretSpecToJson(cSspec, oJson)
? oJson:Emit()
// Result:
// {
// "appName": "myApp",
// "service": "imap",
// "username": "john@example.com"
// }
// ------------------------------------------------------
// 3: service + domain + username
cSspec := "!!|imap|imap.example.com|john"
oSecrets:SecretSpecToJson(cSspec, oJson)
? oJson:Emit()
// Result:
// {
// "service": "imap",
// "domain": "imap.example.com",
// "username": "john"
// }
// ------------------------------------------------------
// 4: appName + service + domain + username
cSspec := "!!myApp|imap|imap.example.com|john"
oSecrets:SecretSpecToJson(cSspec, oJson)
? oJson:Emit()
// Result:
// {
// "appName": "myApp",
// "service": "imap",
// "domain": "imap.example.com",
// "username": "john"
// }
oSecrets:destroy()
oJson:destroy()