| | |
| | | |
| | | 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; |
| | | import com.ard.sample.config.DockConfiguration; |
| | | import com.ard.sample.storage.service.IStorageService; |
| | | import com.ard.oss.service.impl.OssServiceContext; |
| | | import com.ard.sample.utils.MinioStsUtils; |
| | | import io.minio.MinioClient; |
| | | import io.minio.PutObjectArgs; |
| | | import io.minio.credentials.StaticProvider; |
| | |
| | | |
| | | @Autowired |
| | | private OssServiceContext ossService; |
| | | @Autowired |
| | | private MinioStsUtils minioStsUtils; |
| | | |
| | | @Override |
| | | public StsCredentialsDTO getSTSCredentials() { |
| | | CredentialsDTO credentials = ossService.getCredentials(); |
| | | // CredentialsDTO credentials = minioStsUtils.getCredentials(); |
| | | |
| | | //验证一下minio的临时凭证是否可用 |
| | | log.info("验证http临时凭证是否有效:{}", credentials); |
| | | execMinio(DockConfiguration.endpoint, |
| | | credentials.getAccessKeyId(), |
| | | credentials.getAccessKeySecret(), |
| | | credentials.getSecurityToken(), |
| | | OssConfiguration.region, |
| | | DockConfiguration.bucket, |
| | | "test_object_http"); |
| | | |
| | | log.info("验证https临时凭证是否有效:{}", credentials); |
| | | execMinio(OssConfiguration.endpoint, |
| | |
| | | |
| | | return StsCredentialsDTO.builder() |
| | | //机场媒体库minio配置信息用代理地址,桶用机场的桶。 |
| | | .endpoint(OssConfiguration.endpoint) |
| | | .endpoint(DockConfiguration.endpoint) |
| | | .bucket(DockConfiguration.bucket) |
| | | .credentials(credentials) |
| | | .provider(DockConfiguration.provider) |
| | | .objectKeyPrefix(DockConfiguration.objectDirPrefix) |
| | | .region(DockConfiguration.region) |
| | | .provider(OssConfiguration.provider) |
| | | .objectKeyPrefix(OssConfiguration.objectDirPrefix) |
| | | .region(OssConfiguration.region) |
| | | .build(); |
| | | |
| | | // return StsCredentialsDTO.builder() |
| | |
| | | @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(); |