2026-01-23 zwy HTTPS的临时凭证给大疆测试媒体文件上传
| | |
| | | |
| | | @Override |
| | | public StsCredentialsDTO getSTSCredentials() { |
| | | // CredentialsDTO credentials = ossService.getCredentials(); |
| | | CredentialsDTO credentials = minioStsUtils.getCredentials(); |
| | | CredentialsDTO credentials = ossService.getCredentials(); |
| | | // CredentialsDTO credentials = minioStsUtils.getCredentials(); |
| | | |
| | | //验证一下minio的临时凭证是否可用 |
| | | log.info("验证http临时凭证是否有效:{}", credentials); |
| | |
| | | DockConfiguration.bucket, |
| | | "test_object_http"); |
| | | |
| | | // log.info("验证https临时凭证是否有效:{}", credentials); |
| | | // execMinio(OssConfiguration.endpoint, |
| | | // credentials.getAccessKeyId(), |
| | | // credentials.getAccessKeySecret(), |
| | | // credentials.getSecurityToken(), |
| | | // OssConfiguration.region, |
| | | // DockConfiguration.bucket, |
| | | // "test_object_https"); |
| | | log.info("验证https临时凭证是否有效:{}", credentials); |
| | | execMinio(OssConfiguration.endpoint, |
| | | credentials.getAccessKeyId(), |
| | | credentials.getAccessKeySecret(), |
| | | credentials.getSecurityToken(), |
| | | OssConfiguration.region, |
| | | DockConfiguration.bucket, |
| | | "test_object_https"); |
| | | |
| | | return StsCredentialsDTO.builder() |
| | | //机场媒体库minio配置信息用代理地址,桶用机场的桶。 |
| | | .endpoint(DockConfiguration.endpoint) |
| | | .endpoint(OssConfiguration.endpoint) |
| | | .bucket(DockConfiguration.bucket) |
| | | .credentials(credentials) |
| | | .provider(DockConfiguration.provider) |
| | |
| | | import okhttp3.OkHttpClient; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Nonnull; |
| | | import javax.annotation.Nullable; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.ProviderException; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | // 构建适配HTTP协议的OkHttpClient(移除所有SSL相关配置) |
| | | OkHttpClient httpClient = new OkHttpClient.Builder() |
| | | // 保留原代码的连接池配置(禁用连接复用,如需复用可删除此行) |
| | | .connectionPool(new ConnectionPool(0, 1, TimeUnit.SECONDS)) |
| | | .connectionPool(new ConnectionPool(5, 30, TimeUnit.SECONDS)) |
| | | .connectTimeout(10, TimeUnit.SECONDS) // 连接超时 |
| | | .readTimeout(30, TimeUnit.SECONDS) // 读取超时 |
| | | .writeTimeout(30, TimeUnit.SECONDS) // 写入超时 |
| | | .build(); |
| | | |
| | | // 构建 AssumeRoleProvider,使用简化后的HTTP客户端 |
| | | String roleSessionName = "dji-sts-session-" + System.currentTimeMillis(); // 唯一会话名称(必需,避免重复) |
| | | AssumeRoleProvider provider = new AssumeRoleProvider( |
| | | endpoint, // 注意:此处endpoint需改为HTTP地址(如 http://sts.example.com) |
| | | accessKey, // 主账号AccessKey |
| | |
| | | Math.toIntExact(expire), // 凭证过期时间(转int) |
| | | null, // 可选参数(如RoleArn,根据实际SDK调整) |
| | | region, // 地域(如cn-hangzhou) |
| | | null, null, null, // 其他可选参数 |
| | | null, |
| | | roleSessionName, |
| | | null, // 其他可选参数 |
| | | httpClient // 传入HTTP版本的OkHttpClient |
| | | ); |
| | | |
| | | log.info("生成临时凭证条件:{}",provider); |
| | | |
| | | // 获取 STS 临时凭证 |
| | | var stsCredentials = provider.fetch(); |
| | | return new CredentialsDTO(stsCredentials, expire); |