Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed May 11, 2024
1 parent c1447bc commit a55c90f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 27 deletions.
8 changes: 4 additions & 4 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ dependencies {
api(libs.compose.multiplatfrom.gradle.plugin)
implementation(kotlin("script-runtime"))

implementation(libs.aws.s3)
implementation(libs.aws.s3control)
implementation(libs.aws.sts)
implementation(libs.aws.secretsmanager)
// api(libs.aws.s3)
// api(libs.aws.s3control)
// api(libs.aws.sts)
// api(libs.aws.secretsmanager)
}
60 changes: 42 additions & 18 deletions ci-helper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

@file:Suppress("UnstableApiUsage")

import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider
import aws.sdk.kotlin.services.s3.S3Client
import aws.sdk.kotlin.services.s3.model.PutObjectRequest
import aws.smithy.kotlin.runtime.content.FileContent
import aws.smithy.kotlin.runtime.net.url.Url
import io.ktor.client.HttpClient
import io.ktor.client.request.header
import io.ktor.client.request.parameter
Expand All @@ -35,6 +30,12 @@ import io.ktor.util.cio.readChannel
import io.ktor.utils.io.ByteReadChannel
import kotlinx.coroutines.runBlocking
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.internal.impldep.com.amazonaws.auth.AWSStaticCredentialsProvider
import org.gradle.internal.impldep.com.amazonaws.auth.BasicAWSCredentials
import org.gradle.internal.impldep.com.amazonaws.client.builder.AwsClientBuilder
import org.gradle.internal.impldep.com.amazonaws.regions.Regions
import org.gradle.internal.impldep.com.amazonaws.services.s3.AmazonS3ClientBuilder
import org.gradle.internal.impldep.com.amazonaws.services.s3.model.PutObjectRequest

plugins {
kotlin("jvm")
Expand Down Expand Up @@ -259,14 +260,26 @@ open class ReleaseEnvironment {
}

private val s3Client by lazy {
S3Client {
region = getProperty("AWS_REGION")
endpointUrl = Url.parse(getProperty("AWS_BASEURL"))
credentialsProvider = StaticCredentialsProvider {
accessKeyId = getProperty("AWS_ACCESS_KEY_ID")
secretAccessKey = getProperty("AWS_SECRET_ACCESS_KEY")
AmazonS3ClientBuilder
.standard()
.withCredentials(
AWSStaticCredentialsProvider(
BasicAWSCredentials(
getProperty("AWS_ACCESS_KEY_ID"),
getProperty("AWS_SECRET_ACCESS_KEY"),
)
)
)
.withRegion(Regions.US_EAST_1)
.apply {
setEndpointConfiguration(
AwsClientBuilder.EndpointConfiguration(
getProperty("AWS_BASEURL"),
getProperty("AWS_REGION")
)
)
}
}
.build()
}

fun uploadReleaseAsset(
Expand Down Expand Up @@ -303,12 +316,23 @@ open class ReleaseEnvironment {
})
}
if (getProperty("UPLOAD_TO_S3") == "true") {
val request = PutObjectRequest {
bucket = getProperty("AWS_BUCKET")
key = "$tag/$name"
this.contentType = contentType
metadata = mapOf("contentType" to contentType)
body = FileContent(file)
// val bucket = getProperty("AWS_BUCKET")
// val baseUrl = getProperty("AWS_BASEURL").removeSuffix("/")
// client.put("$baseUrl/$bucket/") {
// header("Authorization", "Bearer $token")
// header("x-amz-content-sha256", "UNSIGNED-PAYLOAD")
// parameter("name", name)
// contentType(ContentType.parse(contentType))
// setBody(object : OutgoingContent.ReadChannelContent() {
// override val contentType: ContentType get() = ContentType.parse(contentType)
// override val contentLength: Long = file.length()
// override fun readFrom(): ByteReadChannel {
// return file.readChannel()
// }
// })
// }
val request = PutObjectRequest(getProperty("AWS_BUCKET"), "$tag/$name", file).apply {
this.metadata.contentType = contentType
}
s3Client.putObject(request)
}
Expand Down
13 changes: 8 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ coil = "3.0.0-alpha06"
mongodb-driver-kotlin-coroutine = "4.10.1"
kompendium = "3.14.4"
logback = "1.4.14"
aws = "1.0.41"
aws = "2.25.49"


compose-material3 = "1.2.1"
Expand Down Expand Up @@ -195,8 +195,11 @@ vlcj-javafx = { module = "uk.co.caprica:vlcj-javafx", version = "1.2.0" }
jna = { module = "net.java.dev.jna:jna", version.ref = "jna" }


#// https://mvnrepository.com/artifact/software.amazon.awssdk/s3
#testImplementation("software.amazon.awssdk:s3:2.25.49")

# S3
aws-s3 = { module = "aws.sdk.kotlin:s3", version.ref = "aws" }
aws-sts = { module = "aws.sdk.kotlin:sts", version.ref = "aws" }
aws-s3control = { module = "aws.sdk.kotlin:s3control", version.ref = "aws" }
aws-secretsmanager = { module = "aws.sdk.kotlin:secretsmanager", version.ref = "aws" }
aws-s3 = { module = "software.amazon.awssdk:s3", version.ref = "aws" }
aws-sts = { module = "software.amazon.awssdk:sts", version.ref = "aws" }
aws-s3control = { module = "software.amazon.awssdk:s3control", version.ref = "aws" }
aws-secretsmanager = { module = "software.amazon.awssdk:secretsmanager", version.ref = "aws" }

0 comments on commit a55c90f

Please sign in to comment.