Beispiel #1
0
        // </Snippet_GetServiceSasUriForContainer>

        #endregion

        #region GetServiceSasUriForDirectory

        //-------------------------------------------------
        // Get service SAS for directory
        //-------------------------------------------------

        // <Snippet_GetServiceSasUriForDirectory>
        private static Uri GetServiceSasUriForDirectory(DataLakeDirectoryClient directoryClient,
                                                        string storedPolicyName = null)
        {
            if (directoryClient.CanGenerateSasUri)
            {
                // Create a SAS token that's valid for one hour.
                DataLakeSasBuilder sasBuilder = new DataLakeSasBuilder()
                {
                    // Specify the file system name, the path, and indicate that
                    // the client object points to a directory.
                    FileSystemName = directoryClient.FileSystemName,
                    Resource       = "d",
                    IsDirectory    = true,
                    Path           = directoryClient.Path,
                };

                // If no stored access policy is specified, create the policy
                // by specifying expiry and permissions.
                if (storedPolicyName == null)
                {
                    sasBuilder.ExpiresOn = DateTimeOffset.UtcNow.AddHours(1);
                    sasBuilder.SetPermissions(DataLakeSasPermissions.Read |
                                              DataLakeSasPermissions.Write |
                                              DataLakeSasPermissions.List);
                }
                else
                {
                    sasBuilder.Identifier = storedPolicyName;
                }

                // Get the SAS URI for the specified directory.
                Uri sasUri = directoryClient.GenerateSasUri(sasBuilder);
                Console.WriteLine("SAS URI for ADLS directory is: {0}", sasUri);
                Console.WriteLine();

                return(sasUri);
            }
            else
            {
                Console.WriteLine(@"DataLakeDirectoryClient must be authorized with Shared Key 
                                  credentials to create a service SAS.");
                return(null);
            }
        }