Export and diff configuration
Export the SAND and alerts configuration from two tenants and diff them to find drift. Worth doing before a release, or when a fix lands on staging and has to propagate to prod.
import json
import os
from pathlib import Path
import sasvi
tenants = {
"staging": ("https://staging.viya.example.com", os.environ["STAGING_TOKEN"]),
"prod": ("https://prod.viya.example.com", os.environ["PROD_TOKEN"]),
}
for env, (base_url, token) in tenants.items():
with sasvi.SVIClient(base_url=base_url, auth=sasvi.StaticTokenProvider(token)) as client:
bundle = client.admin.config.export_bundle(include=("sand", "alerts"))
bundle.save_zip(f"vi-config-{env}.zip", overwrite=True)
Path(f"vi-config-{env}.json").write_text(
json.dumps(bundle.to_dict(), indent=2, sort_keys=True),
)
Each tenant needs its own credentials, so build a client per tenant rather than
reusing one. bundle.to_dict() returns a stable, sorted, diffable JSON snapshot.
Point your diff tool at the two JSON files:
diff vi-config-staging.json vi-config-prod.json | less
# or, for a structural diff:
jd vi-config-staging.json vi-config-prod.json
jd is a third-party structural JSON differ.
Apply staging to prod
Once you have reviewed the diff:
import os
import sasvi
prod = sasvi.SVIClient(
base_url="https://prod.viya.example.com",
auth=sasvi.StaticTokenProvider(os.environ["PROD_TOKEN"]),
)
result = prod.admin.config.import_bundle(
"vi-config-staging.zip",
validate_only=True, # dry run first
)
print(result)
# ConfigurationImportResult(ok; sand=ok, alerts=skipped)
# Then for real:
result = prod.admin.config.import_bundle("vi-config-staging.zip")
validate_only=True validates the SAND configuration without persisting it. The
alerts component has no validation-only mode, so it comes back as skipped: true in
the result.
CLI version
sasvi config export writes the full transport archive by default, so ask for the
bundle format explicitly:
SASVI_BASE_URL=https://staging.viya.example.com sasvi config export staging.zip --format bundle
SASVI_BASE_URL=https://prod.viya.example.com sasvi config export prod.zip --format bundle
sasvi --json config inspect staging.zip | jq '.data | del(.path)' > staging.json
sasvi --json config inspect prod.zip | jq '.data | del(.path)' > prod.json
diff staging.json prod.json
Diff the whole solution
The full transport archive is a folder of JSON files, one per object: entity, workflow, reference list, page template, and so on. Unzip two exports and diff the trees to see drift across everything, not only SAND and alerts:
SASVI_BASE_URL=https://staging.viya.example.com sasvi config export staging-full.zip
SASVI_BASE_URL=https://prod.viya.example.com sasvi config export prod-full.zip
mkdir staging prod
unzip -q staging-full.zip -d staging
unzip -q prod-full.zip -d prod
diff -r staging prod | less
Apply a full archive with sasvi config import staging-full.zip --yes, or
admin.config.import_archive from Python. --validate-only covers bundles, not
archives, so for an archive there is no dry run. Export the target first.
Go further
- Configuration guide. Transport archives, bundles, validation, the import flow.
- Admin API reference. The
ConfigurationBundleshape.