| | |
| | | |
| | | import com.ard.common.config.OssConfiguration; |
| | | import com.ard.oss.model.CredentialsDTO; |
| | | import com.ard.sample.common.error.CommonErrorEnum; |
| | | import com.ard.sample.component.mqtt.model.*; |
| | | import com.ard.sample.component.mqtt.service.IMessageSenderService; |
| | | import com.ard.oss.model.StsCredentialsDTO; |
| | |
| | | @Override |
| | | public StsCredentialsDTO getSTSCredentials() { |
| | | CredentialsDTO credentials = ossService.getCredentials(); |
| | | //验证一下minio的临时凭证是否可用 |
| | | log.info("验证临时凭证是否有效:{}", credentials); |
| | | |
| | | log.info("验证https临时凭证是否有效:{}", credentials); |
| | | execMinio(OssConfiguration.endpoint, |
| | | credentials.getAccessKeyId(), |
| | | credentials.getAccessKeySecret(), |
| | | credentials.getSecurityToken(), |
| | | OssConfiguration.region, |
| | | DockConfiguration.bucket, |
| | | "test_object"); |
| | | "test_object_https"); |
| | | |
| | | return StsCredentialsDTO.builder() |
| | | //机场媒体库minio配置信息用代理地址,桶用机场的桶。 |
| | | //.endpoint(OssConfiguration.endpoint) |
| | | .endpoint(DockConfiguration.endpoint) |
| | | // .bucket(OssConfiguration.bucket) |
| | | .bucket(DockConfiguration.bucket) |
| | | // .credentials(ossService.getCredentials()) |
| | | .credentials(credentials) |
| | | .provider(OssConfiguration.provider) |
| | | .objectKeyPrefix(OssConfiguration.objectDirPrefix) |
| | | .region(OssConfiguration.region) |
| | | .build(); |
| | | |
| | | // return StsCredentialsDTO.builder() |
| | | // //机场媒体库minio配置信息用代理地址,桶用机场的桶。 |
| | | // .endpoint(OssConfiguration.endpoint) |
| | | // .bucket(OssConfiguration.bucket) |
| | | //// .credentials(ossService.getCredentials()) |
| | | // .credentials(credentials) |
| | | // .provider(OssConfiguration.provider) |
| | | // .objectKeyPrefix(OssConfiguration.objectDirPrefix) |
| | | // .region(OssConfiguration.region) |
| | | // .build(); |
| | | } |
| | | |
| | | @Override |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_REQUESTS_STORAGE_CONFIG_GET, outputChannel = ChannelName.OUTBOUND) |
| | | public void replyConfigGet(CommonTopicReceiver receiver, MessageHeaders headers) { |
| | | // 20251219 这里是获取上传临时凭证的接口,稍候分析下是否满足条件,如果可以的话就直接回复临时凭证即可 |
| | | RequestsReply reply; |
| | | try { |
| | | reply = RequestsReply.success(this.getSTSCredentials()); |
| | | } catch (Exception e) { |
| | | // 机场1 上送 storage_config_get 时,若 MinIO STS 不可用,原实现会直接抛异常且不回复, |
| | | // 机场会每 5 秒重试一次并持续刷 error.log。这里回一个明确的失败应答,避免消息处理中断。 |
| | | // 底层 MinIOServiceImpl 已打印完整堆栈,此处仅记录关键信息。 |
| | | log.error("获取媒体上传临时凭证失败,gateway={},原因:{}", receiver.getGateway(), e.getMessage()); |
| | | reply = RequestsReply.error(CommonErrorEnum.SYSTEM_ERROR); |
| | | } |
| | | CommonTopicResponse<RequestsReply> response = CommonTopicResponse.<RequestsReply>builder() |
| | | .tid(receiver.getTid()) |
| | | .bid(receiver.getBid()) |
| | | .data(RequestsReply.success(this.getSTSCredentials())) |
| | | .data(reply) |
| | | .timestamp(System.currentTimeMillis()) |
| | | .method(RequestsMethodEnum.STORAGE_CONFIG_GET.getMethod()) |
| | | .build(); |
| | |
| | | String accessKeyId, |
| | | String accessKeySecret, |
| | | String securityToken, |
| | | String region, |
| | | String bucketName, |
| | | String testObjectName) { |
| | | // 1. 替换为你要验证的临时凭证参数(从 getCredentials() 返回的结果中复制) |
| | | try { |
| | | log.info("🔑 正在验证{}临时凭证有效性...", endpoint); |
| | | // 2. 用临时凭证(含 securityToken)初始化 MinIO 客户端 |
| | | MinioClient minioClient = MinioClient.builder() |
| | | .endpoint(endpoint) |
| | | // .credentials(accessKeyId, accessKeySecret) // 核心:传入 securityToken |
| | | .credentialsProvider(new StaticProvider(accessKeyId, accessKeySecret, securityToken)) |
| | | .region("us-east-1") // 和你配置的 region 一致 |
| | | .region(region) // 和你配置的 region 一致 us-east-1 |
| | | .build(); |
| | | |
| | | // 3. 执行验证操作:上传一个测试文件(模拟机场上传媒体文件) |