Azure Blob Storage set CORS Rule

Octopus.Script exported 2016-01-22 by bobjwalker belongs to ‘Azure’ category.

Set a given CORS rule on the specified Azure storage blob container

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Publish Settings File

PublishSettingsFile

Absolute path on the tentacle to the Azure publishsettings file to use. Eg. C:\Azure\Azure.publishsettings

Storage Account

StorageAccount

The Azure Storage Account to use.

Storage Account Key

StorageAccountKey

The primary or secondary key for the Azure Storage Account.

Storage Container

StorageContainer

The storage container to use.

Allowed Headers

AllowedHeaders = "x-ms-blob-content-type","x-ms-blob-content-disposition"

The allowed headers for the CORS rule

Allowed Origins

AllowedOrigins = *

The allowed origins for the CORS rule

Max Age In Seconds

MaxAgeInSeconds = 1800

The max age in seconds that a pre-flight response can be cached on the client for.

Allowed Methods

AllowedMethods = Get

The allowed HTTP methods for the CORS rule

Script body

Steps based on this template will execute the following PowerShell script.

try
{ 
    Import-Module Azure -ErrorAction Stop
}
catch
{
    throw "Windows Azure Powershell not found! Please make sure to install them from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools" 
}

Import-AzurePublishSettingsFile $PublishSettingsFile

$context = New-AzureStorageContext `
    -StorageAccountName $StorageAccount `
    -StorageAccountKey $StorageAccountKey

$container = Get-AzureStorageContainer -Context $context | 
        Where-Object { $_.Name -like $StorageContainer }

if (-not $container)
{
    throw "Azure storage container ($StorageAccount) not found"
}

$corsRules = (@{
    AllowedHeaders=@($AllowedHeaders);
    AllowedOrigins=@($AllowedOrigins);
    MaxAgeInSeconds=$MaxAgeInSeconds;
    AllowedMethods=@($AllowedMethods)})

Set-AzureStorageCORSRule -Context $context -ServiceType Blob -CorsRules $corsRules

Write-Host "Added CORS rule to container: $StorageContainer"

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "745fa985-7022-4b19-a788-2fd77aa5b365",
  "Name": "Azure Blob Storage set CORS Rule",
  "Description": "Set a given CORS rule on the specified Azure storage blob container",
  "Version": 4,
  "ExportedAt": "2016-01-22T04:49:27.549+00:00",
  "ActionType": "Octopus.Script",
  "Author": "bobjwalker",
  "Parameters": [
    {
      "Name": "PublishSettingsFile",
      "Label": "Publish Settings File",
      "HelpText": "Absolute path on the tentacle to the Azure publishsettings file to use. Eg. C:\\Azure\\Azure.publishsettings",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageAccount",
      "Label": "Storage Account",
      "HelpText": "The Azure Storage Account to use.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "StorageAccountKey",
      "Label": "Storage Account Key",
      "HelpText": "The primary or secondary key for the Azure Storage Account.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Name": "StorageContainer",
      "Label": "Storage Container",
      "HelpText": "The storage container to use.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "AllowedHeaders",
      "Label": "Allowed Headers",
      "HelpText": "The allowed headers for the CORS rule",
      "DefaultValue": "\"x-ms-blob-content-type\",\"x-ms-blob-content-disposition\"",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "AllowedOrigins",
      "Label": "Allowed Origins",
      "HelpText": "The allowed origins for the CORS rule",
      "DefaultValue": "*",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "MaxAgeInSeconds",
      "Label": "Max Age In Seconds",
      "HelpText": "The max age in seconds that a pre-flight response can be cached on the client for.",
      "DefaultValue": "1800",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "AllowedMethods",
      "Label": "Allowed Methods",
      "HelpText": "The allowed HTTP methods for the CORS rule",
      "DefaultValue": "Get",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "try\n{ \n    Import-Module Azure -ErrorAction Stop\n}\ncatch\n{\n    throw \"Windows Azure Powershell not found! Please make sure to install them from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools\" \n}\n\nImport-AzurePublishSettingsFile $PublishSettingsFile\n\n$context = New-AzureStorageContext `\n    -StorageAccountName $StorageAccount `\n    -StorageAccountKey $StorageAccountKey\n\n$container = Get-AzureStorageContainer -Context $context | \n        Where-Object { $_.Name -like $StorageContainer }\n\nif (-not $container)\n{\n    throw \"Azure storage container ($StorageAccount) not found\"\n}\n\n$corsRules = (@{\n    AllowedHeaders=@($AllowedHeaders);\n    AllowedOrigins=@($AllowedOrigins);\n    MaxAgeInSeconds=$MaxAgeInSeconds;\n    AllowedMethods=@($AllowedMethods)})\n\nSet-AzureStorageCORSRule -Context $context -ServiceType Blob -CorsRules $corsRules\n\nWrite-Host \"Added CORS rule to container: $StorageContainer\""
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-blob-storage-set-cors.json",
  "Website": "/step-templates/745fa985-7022-4b19-a788-2fd77aa5b365",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJZQC8ez07sKlKTQlcLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzoUSnt8YxXlFuGHSbIaxvj+fip4btkLn1blkWLaF5v03yLhLOYlVuGYfMOMZzNGxCOzhjTJqFkXnjq3Dr1yyvPI3hGl3Ih3zzHHNKudR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6ebZ9788cblTzMrYhu7sf/17IFdtuviJ2ioHA6pMHkoH4CLUeMBU7iGkxuM/YgcdderF9ibRdc7O982F1HpYhjfWUe+x5a6pjop9iNLfoePvlsdZdTSMwfxSmTY20Q0eHnUNzga1edeNmmqbg18aMVR1L9vwSXHF9TfIWBxpKLs2hj3eQeBC0USvp2HHF3eIkRdhFOd6ER8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA/I/4J8AAo/80BciBec4AAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Friday, January 22, 2016