Azure-cli: az storage account generate-sas --expiry precision

Created on 25 Aug 2017  路  7Comments  路  Source: Azure/azure-cli

Description

Attempting to generate a sas token with seconds precision fails:

az storage account generate-sas: error: argument --expiry: invalid datetime_type value: '2017-08-25T12:27:03'

In Powershell, the Get-Date cmdlet provides quick format options for SortableDateTimePattern and UniversalSortableDateTimePattern which both include seconds. Using these formats results in the error above.

Fails: 2017-08-25T12:27:03
Succeeds: 2017-08-25T12:27Z

Similar to closed issue #1560


Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: interactive script

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here: 2.0.14

OS Version: What OS and version are you using?
Answer here: Mac OSX Sierra 10.12.6

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: Powershell on OSX

Storage

Most helpful comment

I ended up using the SortableDateTimePattern and concatenating a 'Z' on the end.

For anyone reading this - the following (in PowerShell) also works:

--expiry (Get-Date).AddMinutes(30).ToString("yyyy-MM-dTH:mZ")

All 7 comments

To clarify, are you saying that you can't use seconds to generate a SAS in PS either or simply that the format you got from a PS cmdlet fails in the CLI?

The latter. For some context, I'm currently switching from using the ARM PS cmdlets to Azure CLI, and using the New-AzureStorageContainerSASToken cmdlet I am able to specify an -ExpiryTime (Get-Date).AddHours(4) without issues.

The formats for dates in PS include seconds which isn't allowed in the format specified for the CLI: (Y-m-d'T'H:M'Z'). My expectation would be for the seconds precision to not make a difference in this case and should be allowed as part of the -expiry argument in the CLI.

@troydai That does resolve the issue I had. I ended up using the SortableDateTimePattern and concatenating a 'Z' on the end. It's a bummer that there's not an option available in PS that fits this pattern but that's not a problem I expect you guys to solve.

Thanks!

You're welcome, @Zureka .

Can you please help me how to auto generate the SAS Token for every 3 or 5 seconds through powershell and how the resources can access the auto generated SAS Token

I ended up using the SortableDateTimePattern and concatenating a 'Z' on the end.

For anyone reading this - the following (in PowerShell) also works:

--expiry (Get-Date).AddMinutes(30).ToString("yyyy-MM-dTH:mZ")

Was this page helpful?
0 / 5 - 0 ratings