<jupyter_start><jupyter_text>Copyright © 2020, SAS Institute Inc., Cary, NC, USA.  All Rights Reserved. SPDX-License-Identifier: Apache-2.0  Configure an Azure Container Publishing Destination_**Important:** This example should be used for SAS Viya 2021.1.3 and later stable releases._In order to create an Azure destination, you must complete the following steps:1. Establish a connection and define URLs.2. Get an authorization token.3. Find a valid domain with Azure credentials.4. Create credentials for a specific user or group and define a credential domain.5. Submit an API post to create an Azure destination._Note: An example of deleting a destination is also included._  Establish a Connection and Define URLs<jupyter_code>import sys
sys.path.append('..')
import mmAuthorization

import requests
import json, os, pprint
import base64
host_name= "localhost"
port = "8080"

host_url="http://" + host_name + ":" + port
destination_url = host_url + "/modelPublish/destinations/"
modelrepo_url = host_url + "/modelRepository/models/"
publishmodel_url = host_url + "/modelPublish/models"
domains_url = host_url + "/credentials/domains"
print(host_url)<jupyter_output><empty_output><jupyter_text>Get an Authorization Token and Define Headers<jupyter_code>mm_auth = mmAuthorization.mmAuthorization("myAuth")

admin_userId = '<SAS_user_admin_ID>'
user_passwd =  '<<PASSWORD>>'

sas_userId = '<SAS_user_ID>'

admin_auth_token = mm_auth.get_auth_token(host_url, admin_userId, user_passwd)

credential_admin_headers = {
    mmAuthorization.AUTHORIZATION_HEADER: mmAuthorization.AUTHORIZATION_TOKEN + admin_auth_token
}

credential_domain_headers = {
    "If-Match":"false",
    "Content-Type":"application/json",
    mmAuthorization.AUTHORIZATION_HEADER: mmAuthorization.AUTHORIZATION_TOKEN + admin_auth_token
}

credential_user_headers = {
    "If-Match":"false",
    "Content-Type":"application/json",
    mmAuthorization.AUTHORIZATION_HEADER: mmAuthorization.AUTHORIZATION_TOKEN + admin_auth_token
}

destination_azure_headers = {
    "If-Match":"false",
    "Content-Type":"application/vnd.sas.models.publishing.destination.azure+json",
    mmAuthorization.AUTHORIZATION_HEADER: mmAuthorization.AUTHORIZATION_TOKEN + admin_auth_token
}

print(admin_auth_token)<jupyter_output><empty_output><jupyter_text>Create a Credential Domain<jupyter_code>domain_name = '<Domain_Name>'
description = '<Domain_Description>'

my_domain_url = domains_url + "/" + domain_name
domain_attrs = {
    "id": domain_name,
    "type": "base64",
    "description": description
}

domain = requests.put(my_domain_url, 
                       data=json.dumps(domain_attrs), headers=credential_domain_headers)

print(domain)
pprint.pprint(domain.json())<jupyter_output><empty_output><jupyter_text>Create User Credentials_**Note:** The credential properties were updated in the SAS Viya 2021.1.3 stable release._<jupyter_code>domain_name = '<Domain_Name>'
my_domain_url = domains_url + "/" + domain_name

user_credential_name = sas_userId
my_credential_url = my_domain_url + "/users/" + user_credential_name

clientID = '<Azure_Container_Registry_Client_ID>'
clientSecret = '<Azure_Container_Registry_Secret>'

encoded_clientID = str(base64.b64encode(clientID.encode("utf-8")), "utf-8")
encoded_clientSecret = str(base64.b64encode(clientSecret.encode("utf-8")), "utf-8")

credential_attrs = {
    "domainId":domain_name,
    "identityType":"user",
    "identityId":user_credential_name,
    "domainType":"base64",
    "properties":{"clientId":encoded_clientID},
    "secrets":{"clientSecret":encoded_clientSecret}
}

credential = requests.put(my_credential_url, 
                       data=json.dumps(credential_attrs), headers=credential_user_headers)

print(credential)
pprint.pprint(credential.json())<jupyter_output><empty_output><jupyter_text>Create an Azure Destination<jupyter_code>dest_name = '<Destination_Name>'
domainName = '<Domain_Name>'
baseRepoUrl = '<Azure_Container_Registry_Base_URL>'

tenantId = '<Azure_Tenant_ID>'    
subscriptionID = '<Azure_Subscription_ID>'
resourceGroupName = '<Azure_Resource_Group_Name>'
k8sClusterName = '<Azure_Kubernetes_Service_Cluster_Name>'
region= '<region>' # Optional. The location (for example, eastus) of the resource in the cloud-based or Docker registry.


destination_attrs = {
    'name': dest_name,
    'destinationType': 'azure',
    'properties': [{'name': "credDomainId", "value": domainName},
                   {"name": "baseRepoUrl", "value": baseRepoUrl},
                   {'name': "tenantId", "value": tenantId},
                   {'name': "subscriptionId", "value": subscriptionID},
                   {'name': "resourceGroupName", "value": resourceGroupName},
                   {'name': "kubernetesCluster", "value": k8sClusterName},
                   {'name': "region", "value": region}]}

destination = requests.post(destination_url, 
                       data=json.dumps(destination_attrs), headers=destination_azure_headers)

print(destination)
pprint.pprint(destination.json())<jupyter_output><empty_output><jupyter_text>Delete a Destination<jupyter_code>deletedURL = destination_url + dest_name

destination = requests.delete(deletedURL, headers=credential_admin_headers)

print(deletedURL)
print(destination)
pprint.pprint(destination.json())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11536297129994373, 'fraction_numerical': 0.008816357156255863, 'mean_word_length': 5.665, 'pattern_counts': {'":': 26, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '562978', 'license': 'Apache-2.0', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1646, 'n_words': 323, 'path': 'addons/destinations/CreateAzureDestination.ipynb', 'repo_name': 'kaponte75/open-model-manager-resources', 'size': '5338'}