Skip to content

Commit 5d8bffa

Browse files
liaobwRock-520
authored andcommitted
重构FileAppService中的getStsTemporaryCredential方法,增加对本地驱动的临时凭证处理,并在FileProcessAppService中整合使用FileAppService获取STS Token,提升代码复用性和可读性。
1 parent ee0c53c commit 5d8bffa

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

backend/super-magic-module/src/Application/SuperAgent/Service/FileProcessAppService.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -364,24 +364,12 @@ public function refreshStsToken(RefreshStsTokenRequestDTO $requestDTO): array
364364
$storageType = StorageBucketType::Private->value;
365365
$expires = 7200; // 凭证有效期2小时
366366

367-
// 调用文件服务获取STS Token
368-
$data = $this->fileDomainService->getStsTemporaryCredential(
369-
$organizationCode,
370-
$storageType,
371-
$workDir,
372-
$expires
373-
);
367+
// 创建用户授权对象
368+
$userAuthorization = new MagicUserAuthorization();
369+
$userAuthorization->setOrganizationCode($organizationCode);
374370

375-
// 如果是本地驱动,那么增加一个临时 key
376-
if ($data['platform'] === AdapterName::LOCAL) {
377-
$localCredential = 'local_credential:' . IdGenerator::getUniqueId32();
378-
$data['temporary_credential']['dir'] = $organizationCode . '/' . $data['temporary_credential']['dir'];
379-
$data['temporary_credential']['credential'] = $localCredential;
380-
$data['temporary_credential']['read_host'] = env('FILE_LOCAL_DOCKER_READ_HOST', '');
381-
$data['temporary_credential']['host'] = env('FILE_LOCAL_DOCKER_WRITE_HOST', '');
382-
$this->cache->set($localCredential, ['organization_code' => $organizationCode], (int) ($data['expires'] - time()));
383-
}
384-
return $data;
371+
// 使用统一的FileAppService获取STS Token
372+
return $this->fileAppService->getStsTemporaryCredential($userAuthorization, $storageType, $workDir, $expires);
385373
} catch (Throwable $e) {
386374
$this->logger->error(sprintf(
387375
'刷新STS Token失败: %s,组织编码: %s,沙箱ID: %s',

0 commit comments

Comments
 (0)