Can't list file system of azure datalake with javascript

断了今生、忘了曾经 提交于 2021-01-29 05:02:13

问题


I'm trying to list the paths within a file system in Azure datalake using this code :

I'm able to retrieve ${fileSystem.name} but getting permissions denied with .listPaths()

node:15660) UnhandledPromiseRejectionWarning: RestError: This request is not authorized to perform this operation using this permission.

i'm not sure what permissions I need to provide, the service principle has owner access over the datalake storage account and also has the api permissions

the code:

const { DataLakeServiceClient } = require('@azure/storage-file-datalake');

require('dotenv').config();

const account = 'xxx';

const defaultAzureCredential = new DefaultAzureCredential();

const datalakeServiceClient = new DataLakeServiceClient(
    `https://${account}.dfs.core.windows.net`,
    defaultAzureCredential
);

async function main() {
    let i = 1;
    let iter = await datalakeServiceClient.listFileSystems();

    for await (const fileSystem of iter) {
        console.log(`File system ${i++}: ${fileSystem.name} `);
        const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystem.name);
        let iter = await fileSystemClient.listPaths();
        for await (const path of iter) {
            console.log(`Path ${i}: ${path.name}, is directory: ${path.isDirectory}`);
        }

    }
}

main();


回答1:


To fix the issue, navigate to your data lake gen2 storage account in the portal -> Access control (IAM) -> assign a Storage Blob Data Owner role to your service principal.

Then the code works fine:



来源:https://stackoverflow.com/questions/61662089/cant-list-file-system-of-azure-datalake-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!