none
StorageAccountUpdateParameters - How do I enable Secure Transfer Only? RRS feed

  • Question

  • Hi folks,

    I'm trying my hand at a couple of Python scripts to check for Secure Transfer Only set to true on an Azure Storage account. I can't seem to get the right syntax for StorageAccountUpdateParameters (enable_https_traffic_only) and it isn't really documented with a good example. Has anyone else got this to work? If so, how'd you do it?

    Cheers

    Chris.

    Tuesday, July 16, 2019 2:38 PM

All replies

  • Chris,

    You should be able to simply list the parameter you want to change and the new value.

    from azure.common.credentials import ServicePrincipalCredentials
    from azure.mgmt.storage import StorageManagementClient
    from azure.mgmt.storage.models import StorageAccountUpdateParameters
    
    # Tenant ID for your Azure subscription
    TENANT_ID = 'TENANT ID'
    
    SUBSCRIPTION_ID = 'SUBSCRIPTION ID'
    
    # Your service principal App ID
    CLIENT = 'APP ID'
    
    # Your service principal password
    KEY = 'APP SECRET'
    
    GROUP_NAME = 'RESOURCE GROUP NAME'
    
    STORAGE_ACCOUNT_NAME = 'STORAGE ACCOUNT NAME'
    
    credentials = ServicePrincipalCredentials(
        client_id = CLIENT,
        secret = KEY,
        tenant = TENANT_ID
    )
    
    storage_client = StorageManagementClient(credentials, SUBSCRIPTION_ID)
    
    storage_account = storage_client.storage_accounts.get_properties(
        GROUP_NAME, STORAGE_ACCOUNT_NAME)
    
    print("Original Setting: ")
    print(storage_account.enable_https_traffic_only)
    
    modified_storage_account = storage_client.storage_accounts.update(
        GROUP_NAME, STORAGE_ACCOUNT_NAME,
        StorageAccountUpdateParameters(
            enable_https_traffic_only = True
        )
    )
    
    print("Modified Setting: ")
    print(modified_storage_account.enable_https_traffic_only)
    Are you getting a specific error message that could shed some light on what is wrong with the query?

    Thursday, July 18, 2019 7:08 PM
    Moderator