Amazon.Transfer.Model.InvalidRequestException:无法为LOGICAL Hom



朋友,

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

如果我对HomeDirectoryMappings进行注释并将HomeDirectoryType设置为HomeDirectoryType.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;
}

EDIT:我在所有示例中注意到的一件事是s3 bucket文件夹名称被提到为<s3bucket>/home/username。我需要这个文件夹结构使它工作吗?

我发现不需要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"
};

相关内容

  • 没有找到相关文章

最新更新