0

朋友们,

我有一个Dictionary<int, string>包含 DepartmentId 列表及其 s3 文件夹名称的列表。例如,{ {key=1, value="dept-1"}, {key=2, value="dept-2"} }等等。对于每个 s3 文件夹,我想创建一个user-dept-group-{DepartmentId}逻辑映射到其 SFTP 服务器文件夹的用户。例如,user-dept-group-1将有一个逻辑文件夹dept-1映射到my-s3-bucket/dept-1aws sftp 服务器。下面是我使用的代码,我总是Cannot set HomeDirectory for LOGICAL HomeDirectoryType出错。

如果我评论HomeDirectoryMappings并将 设置HomeDirectoryTypeHomeDirectoryType.PATH,那么我会看到用户被创建。

public async Task<List<CreateUserResponse>> SetupSftpUser(Dictionary<int, string> masterDeptFolders)
{
    var result = new List<CreateUserResponse>();
    var awsTransferClient = new AmazonTransferClient(AwsAccessKey, AwsSecretKey, RegionEndpoint.USEast1);
    foreach (var (key, folder) in masterDeptFolders)
    {
    var createUserRequest = new CreateUserRequest
    {
        HomeDirectory = $"/{ParentBucketName}/{folder}/",
        HomeDirectoryMappings = new List<HomeDirectoryMapEntry>{new HomeDirectoryMapEntry{Entry = $"/{folder}", Target = $"/{ParentBucketName}/{folder}" } },
        HomeDirectoryType = HomeDirectoryType.LOGICAL,
        // Policy = GetSftpPolicy(),
        Tags = GetTags(key, folder),
        ServerId = SftpServerId,
        UserName = $"user-dept-group-{key}",
        Role = SftpRole,
        //SshPublicKeyBody = "MY_DEPT_SSH.PUB_FILE"
    };

    var response = await awsTransferClient.CreateUserAsync(createUserRequest);
    if (response.HttpStatusCode == HttpStatusCode.OK)
    {
        result.Add(response);
    }
    }

    return result;
}

编辑:我在所有示例中注意到的一件事是 s3 存储桶文件夹名称被称为<s3bucket>/home/username. 我是否需要具有此文件夹结构才能使其正常工作?

4

1 回答 1

0

我发现HomeDirectory不需要 并且 Entry 值必须设置为\。下面是createUserRequest外观。

var createUserRequest = new CreateUserRequest
{
    HomeDirectoryMappings = new List<HomeDirectoryMapEntry>{new HomeDirectoryMapEntry{Entry = "/", Target = $"/{ParentBucketName}/{folder}" } },
    HomeDirectoryType = HomeDirectoryType.LOGICAL,
    // Policy = GetSftpPolicy(),
    Tags = GetTags(key, folder),
    ServerId = SftpServerId,
    UserName = $"user-dept-group-{key}",
    Role = SftpRole,
    //SshPublicKeyBody = "MY_DEPT_SSH.PUB_FILE"
};
于 2020-07-17T14:26:21.283 回答