diff --git a/example.env b/example.env index 9e191a3..2070268 100644 --- a/example.env +++ b/example.env @@ -1,8 +1,9 @@ KERBEROS_PASSWORD="test" MONGO_URI="mongodb://127.0.0.1:27017/" DATABASE_URI="postgres:///postgres?sslmode=disable" -DATASTORE_DATA_PATH="10.CTR_JWVJ_datastore/ds/1/data" -DATASTORE_DATA_URL="datastoreurl.com" -S3_BUCKET_NAME="s3_bucket_name" -S3_KEY="key" -S3_SECRET="secret" +PN_NBA_CONFIG_S3_PATH="10.CTR_JWVJ_datastore/ds/1/data" +PN_NBA_CONFIG_S3_ENDPOINT="https://datastoreurl.com" +PN_NBA_CONFIG_S3_REGION="us-east-1" +PN_NBA_CONFIG_S3_BUCKET="s3_bucket_name" +PN_NBA_CONFIG_S3_ACCESS_KEY="key" +PN_NBA_CONFIG_S3_ACCESS_SECRET="secret" diff --git a/globals/globals.go b/globals/globals.go index f7061fe..f39bb30 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -3,9 +3,10 @@ package globals import ( "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/plogger-go" - "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go-v2/service/s3" ) var Logger = plogger.NewLogger() var NEXServer *nex.Server -var S3Client *s3.S3 +var S3Client *s3.Client +var S3PresignClient *PresignClient diff --git a/globals/s3_object_size.go b/globals/s3_object_size.go new file mode 100644 index 0000000..fba5fc4 --- /dev/null +++ b/globals/s3_object_size.go @@ -0,0 +1,32 @@ +package globals + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/s3" +) + +func S3HeadRequest(bucket, key string) (*s3.HeadObjectOutput, error) { + input := &s3.HeadObjectInput{ + Bucket: &bucket, + Key: &key, + } + + res, err := S3Client.HeadObject(context.TODO(), input) + + if err != nil { + return nil, err + } + + return res, nil +} + +func S3ObjectSize(bucket, key string) (uint64, error) { + res, err := S3HeadRequest(bucket, key) + + if err != nil { + return 0, err + } + + return uint64(res.ContentLength), nil +} diff --git a/globals/s3_presigned_post.go b/globals/s3_presigned_post.go new file mode 100644 index 0000000..ca4c688 --- /dev/null +++ b/globals/s3_presigned_post.go @@ -0,0 +1,158 @@ +package globals + +import ( + "context" + "crypto/hmac" + "crypto/sha256" + "encoding/base64" + "encoding/hex" + "encoding/json" + "fmt" + "regexp" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" +) + +type PresignClient struct { + cfg aws.Config +} + +type PostObjectInput struct { + // Key name + Key string + + // The name of the bucket to presign the post to + Bucket string + + // Expiration - The number of seconds the presigned post is valid for. + ExpiresIn time.Duration + + // A list of conditions to include in the policy. Each element can be either a list or a structure. + // For example: + // [ + // {"acl": "public-read"}, ["content-length-range", 2, 5], ["starts-with", "$success_action_redirect", ""] + // ] + Conditions []interface{} +} + +type PresignedPostObject struct { + URL string `json:"url"` + Key string `json:"key"` + Policy string `json:"policy"` + Credential string `json:"credential"` + SecurityToken string `json:"securityToken,omitempty"` + Signature string `json:"signature"` + Date string `json:"date"` +} + +func (presignClient *PresignClient) PresignPostObject(input *PostObjectInput) (*PresignedPostObject, error) { + credentials, err := presignClient.cfg.Credentials.Retrieve(context.TODO()) + if err != nil { + return nil, err + } + + expirationTime := time.Now().Add(input.ExpiresIn).UTC() + dateString := expirationTime.Format("20060102") + dateTimeString := expirationTime.Format("20060102T150405Z") + + credentialString := fmt.Sprintf("%s/%s/%s/s3/aws4_request", credentials.AccessKeyID, dateString, presignClient.cfg.Region) + + policyDocument, err := createPolicyDocument(expirationTime, input.Bucket, input.Key, credentialString, &credentials.SessionToken, input.Conditions) + if err != nil { + return nil, err + } + + signature := createSignature(credentials.SecretAccessKey, presignClient.cfg.Region, dateString, policyDocument) + + // * This is the best way, that I can find, to format the + // * s3 endpoint URL without needing to pass it in twice + // * (first duirng s3 setup, then when creating this client) + exp := regexp.MustCompile(`^(https://)(.*)`) + endpoint, err := presignClient.cfg.EndpointResolverWithOptions.ResolveEndpoint("", "") + if err != nil { + return nil, err + } + + url := exp.ReplaceAllString(endpoint.URL, fmt.Sprintf("${1}%s.${2}", input.Bucket)) + + presignedPostObject := &PresignedPostObject{ + Key: input.Key, + Policy: policyDocument, + Signature: signature, + URL: url, + Credential: credentialString, + SecurityToken: credentials.SessionToken, + Date: dateTimeString, + } + + return presignedPostObject, nil +} + +func NewPresignClient(cfg aws.Config) *PresignClient { + return &PresignClient{cfg} +} + +func createPolicyDocument(expirationTime time.Time, bucket string, key string, credentialString string, securityToken *string, extraConditions []interface{}) (string, error) { + + doc := map[string]interface{}{} + doc["expiration"] = expirationTime.Format("2006-01-02T15:04:05.000Z") + + // conditions + conditions := []interface{}{} + conditions = append(conditions, map[string]string{ + "bucket": bucket, + }) + + conditions = append(conditions, []string{ + "starts-with", "$key", key, + }) + + conditions = append(conditions, map[string]string{ + "x-amz-credential": credentialString, + }) + + if securityToken != nil { + conditions = append(conditions, map[string]string{ + "x-amz-security-token": *securityToken, + }) + } + + conditions = append(conditions, map[string]string{ + "x-amz-algorithm": "AWS4-HMAC-SHA256", + }) + + conditions = append(conditions, map[string]string{ + "x-amz-date": expirationTime.Format("20060102T150405Z"), + }) + + // other conditions + conditions = append(conditions, extraConditions...) + + doc["conditions"] = conditions + + // base64 encoded json string + jsonBytes, err := json.Marshal(doc) + if err != nil { + return "", err + } + + return base64.StdEncoding.EncodeToString(jsonBytes), nil +} + +func createSignature(secretKey string, region string, dateString string, stringToSign string) string { + + // Helper to make the HMAC-SHA256. + makeHmac := func(key []byte, data []byte) []byte { + hash := hmac.New(sha256.New, key) + hash.Write(data) + return hash.Sum(nil) + } + + h1 := makeHmac([]byte("AWS4"+secretKey), []byte(dateString)) + h2 := makeHmac(h1, []byte(region)) + h3 := makeHmac(h2, []byte("s3")) + h4 := makeHmac(h3, []byte("aws4_request")) + signature := makeHmac(h4, []byte(stringToSign)) + return hex.EncodeToString(signature) +} diff --git a/go.mod b/go.mod index e7c3a3d..39cbf13 100644 --- a/go.mod +++ b/go.mod @@ -3,19 +3,35 @@ module github.com/PretendoNetwork/nintendo-badge-arcade-secure go 1.19 require ( - github.com/PretendoNetwork/nex-go v1.0.16 - github.com/PretendoNetwork/nex-protocols-go v1.0.22 + github.com/PretendoNetwork/nex-go v1.0.20 + github.com/PretendoNetwork/nex-protocols-go v1.0.25 github.com/PretendoNetwork/plogger-go v1.0.2 - github.com/aws/aws-sdk-go v1.44.239 + github.com/aws/aws-sdk-go-v2 v1.18.0 + github.com/aws/aws-sdk-go-v2/config v1.18.25 + github.com/aws/aws-sdk-go-v2/credentials v1.13.24 + github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.7 go.mongodb.org/mongo-driver v1.11.4 ) require ( + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.25 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.28 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.2 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect + github.com/aws/smithy-go v1.13.5 // indirect github.com/fatih/color v1.15.0 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jwalton/go-supportscolor v1.1.0 // indirect github.com/klauspost/compress v1.16.4 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index f91c558..0e2ed33 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,45 @@ -github.com/PretendoNetwork/nex-go v1.0.16 h1:g2lJW8G+WOS6/8qsgQ0+jLlzemjJ60tQtLqloLTjElo= -github.com/PretendoNetwork/nex-go v1.0.16/go.mod h1:Bx2ONeSefnbJyE0IDIwGopxrjRrnszOV/uQv74Cx+m0= -github.com/PretendoNetwork/nex-protocols-go v1.0.22 h1:hlnwh006p68HVoZpKfk8fGMpLp6NTzBHPz1OhS7Y3l0= -github.com/PretendoNetwork/nex-protocols-go v1.0.22/go.mod h1:Bt7hI7hJ+8r6UU5LSs+3xx4xzsvMVeEUkAW8Cg3lGjQ= +github.com/PretendoNetwork/nex-go v1.0.20 h1:jkd+lbz7ieaixJjCBjPnBvcCMuL0+k7VShp3HakRNQI= +github.com/PretendoNetwork/nex-go v1.0.20/go.mod h1:Bx2ONeSefnbJyE0IDIwGopxrjRrnszOV/uQv74Cx+m0= +github.com/PretendoNetwork/nex-protocols-go v1.0.25 h1:cb+5TQJwNq+J3uT8phxKwLFM9vZuLiNvqHRoY9RZ2UY= +github.com/PretendoNetwork/nex-protocols-go v1.0.25/go.mod h1:Zfwl+WgHDqCIFs6PxoqzOu5cXdDXHPHic3VBn962/es= github.com/PretendoNetwork/plogger-go v1.0.2 h1:vWKEnEmJJzYwqLxLyiSsAvCrZV6qnnu/a0GQOjIfzY0= github.com/PretendoNetwork/plogger-go v1.0.2/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= -github.com/aws/aws-sdk-go v1.44.239 h1:AenB6byCYGSBb30q99CGYqFbqpLpWrTidzm7MzxtuPo= -github.com/aws/aws-sdk-go v1.44.239/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= +github.com/aws/aws-sdk-go-v2 v1.18.0 h1:882kkTpSFhdgYRKVZ/VCgf7sd0ru57p2JCxz4/oN5RY= +github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 h1:dK82zF6kkPeCo8J1e+tGx4JdvDIQzj7ygIoLg8WMuGs= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10/go.mod h1:VeTZetY5KRJLuD/7fkQXMU6Mw7H5m/KP2J5Iy9osMno= +github.com/aws/aws-sdk-go-v2/config v1.18.25 h1:JuYyZcnMPBiFqn87L2cRppo+rNwgah6YwD3VuyvaW6Q= +github.com/aws/aws-sdk-go-v2/config v1.18.25/go.mod h1:dZnYpD5wTW/dQF0rRNLVypB396zWCcPiBIvdvSWHEg4= +github.com/aws/aws-sdk-go-v2/credentials v1.13.24 h1:PjiYyls3QdCrzqUN35jMWtUK1vqVZ+zLfdOa/UPFDp0= +github.com/aws/aws-sdk-go-v2/credentials v1.13.24/go.mod h1:jYPYi99wUOPIFi0rhiOvXeSEReVOzBqFNOX5bXYoG2o= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 h1:jJPgroehGvjrde3XufFIJUZVK5A2L9a3KwSFgKy9n8w= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3/go.mod h1:4Q0UFP0YJf0NrsEuEYHpM9fTSEVnD16Z3uyEF7J9JGM= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 h1:kG5eQilShqmJbv11XL1VpyDbaEJzWxd4zRiCG30GSn4= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33/go.mod h1:7i0PF1ME/2eUPFcjkVIwq+DOygHEoK92t5cDqNgYbIw= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 h1:vFQlirhuM8lLlpI7imKOMsjdQLuN9CPi+k44F/OFVsk= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27/go.mod h1:UrHnn3QV/d0pBZ6QBAEQcqFLf8FAzLmoUfPVIueOvoM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 h1:gGLG7yKaXG02/jBlg210R7VgQIotiQntNhsCFejawx8= +github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34/go.mod h1:Etz2dj6UHYuw+Xw830KfzCfWGMzqvUTCjUj5b76GVDc= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.25 h1:AzwRi5OKKwo4QNqPf7TjeO+tK8AyOK3GVSwmRPo7/Cs= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.25/go.mod h1:SUbB4wcbSEyCvqBxv/O/IBf93RbEze7U7OnoTlpPB+g= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 h1:y2+VQzC6Zh2ojtV2LoC0MNwHWc6qXv/j2vrQtlftkdA= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11/go.mod h1:iV4q2hsqtNECrfmlXyord9u4zyuFEJX9eLgLpSPzWA8= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.28 h1:vGWm5vTpMr39tEZfQeDiDAMgk+5qsnvRny3FjLpnH5w= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.28/go.mod h1:spfrICMD6wCAhjhzHuy6DOZZ+LAIY10UxhUmLzpJTTs= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 h1:0iKliEXAcCa2qVtRs7Ot5hItA2MsufrphbRFlz1Owxo= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27/go.mod h1:EOwBD4J4S5qYszS5/3DpkejfuK+Z5/1uzICfPaZLtqw= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.2 h1:NbWkRxEEIRSCqxhsHQuMiTH7yo+JZW1gp8v3elSVMTQ= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.2/go.mod h1:4tfW5l4IAB32VWCDEBxCRtR9T4BWy4I4kr1spr8NgZM= +github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1 h1:O+9nAy9Bb6bJFTpeNFtd9UfHbgxO1o4ZDAM9rQp5NsY= +github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1/go.mod h1:J9kLNzEiHSeGMyN7238EjJmBpCniVzFda75Gxl/NqB8= +github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 h1:UBQjaMTCKwyUYwiVnUt6toEJwGXsLBI6al083tpjJzY= +github.com/aws/aws-sdk-go-v2/service/sso v1.12.10/go.mod h1:ouy2P4z6sJN70fR3ka3wD3Ro3KezSxU6eKGQI2+2fjI= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 h1:PkHIIJs8qvq0e5QybnZoG1K/9QTrLr9OsqCIo59jOBA= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10/go.mod h1:AFvkxc8xfBe8XA+5St5XIHHrQQtkxqrRincx4hmMHOk= +github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 h1:2DQLAKDteoEDI8zpCzqBMaZlJuoE9iTYD0gFmXVax9E= +github.com/aws/aws-sdk-go-v2/service/sts v1.19.0/go.mod h1:BgQOMsg8av8jset59jelyPW7NoZcZXLVpDsXunGDrk8= +github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8= +github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -16,9 +50,8 @@ github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= @@ -81,8 +114,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -97,14 +128,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -112,7 +141,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -122,7 +150,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/init.go b/init.go index 8c8d2e0..16d76a1 100644 --- a/init.go +++ b/init.go @@ -1,8 +1,16 @@ package main import ( - "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" + "context" + "os" + "github.com/PretendoNetwork/plogger-go" + "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" + "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/credentials" + "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/joho/godotenv" ) @@ -10,9 +18,37 @@ var logger = plogger.NewLogger() func init() { err := godotenv.Load() + if err != nil { logger.Warning("Error loading .env file") } + s3Endpoint := os.Getenv("PN_NBA_CONFIG_S3_ENDPOINT") + s3Region := os.Getenv("PN_NBA_CONFIG_S3_REGION") + s3AccessKey := os.Getenv("PN_NBA_CONFIG_S3_ACCESS_KEY") + s3AccessSecret := os.Getenv("PN_NBA_CONFIG_S3_ACCESS_SECRET") + + staticCredentials := credentials.NewStaticCredentialsProvider(s3AccessKey, s3AccessSecret, "") + + endpointResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) { + return aws.Endpoint{ + URL: s3Endpoint, + }, nil + }) + + cfg, err := config.LoadDefaultConfig( + context.TODO(), + config.WithRegion(s3Region), + config.WithCredentialsProvider(staticCredentials), + config.WithEndpointResolverWithOptions(endpointResolver), + ) + + if err != nil { + panic(err) + } + + globals.S3Client = s3.NewFromConfig(cfg) + globals.S3PresignClient = globals.NewPresignClient(cfg) + database.ConnectAll() } diff --git a/nex/datastore/change_meta.go b/nex/datastore/change_meta.go index 4527b48..cbceae8 100644 --- a/nex/datastore/change_meta.go +++ b/nex/datastore/change_meta.go @@ -6,7 +6,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/utility" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/nex/datastore/complete_post_object.go b/nex/datastore/complete_post_object.go index 9130769..75bef8f 100644 --- a/nex/datastore/complete_post_object.go +++ b/nex/datastore/complete_post_object.go @@ -4,7 +4,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/nex/datastore/complete_update_object.go b/nex/datastore/complete_update_object.go index 7dcf31c..61b7fee 100644 --- a/nex/datastore/complete_update_object.go +++ b/nex/datastore/complete_update_object.go @@ -4,7 +4,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/nex/datastore/get_persistence_info.go b/nex/datastore/get_persistence_info.go index 5affc6c..6f7e289 100644 --- a/nex/datastore/get_persistence_info.go +++ b/nex/datastore/get_persistence_info.go @@ -4,7 +4,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/nex/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go b/nex/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go index bdec679..c110e34 100644 --- a/nex/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go +++ b/nex/datastore/nintendo-badge-arcade/get_meta_by_owner_id.go @@ -6,7 +6,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/utility" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" datastore_nintendo_badge_arcade "github.com/PretendoNetwork/nex-protocols-go/datastore/nintendo-badge-arcade" ) diff --git a/nex/datastore/post_meta_binary.go b/nex/datastore/post_meta_binary.go index 3fc9585..b4bbf3a 100644 --- a/nex/datastore/post_meta_binary.go +++ b/nex/datastore/post_meta_binary.go @@ -7,7 +7,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/utility" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/nex/datastore/prepare_get_object.go b/nex/datastore/prepare_get_object.go index 86bbcd2..34103a3 100644 --- a/nex/datastore/prepare_get_object.go +++ b/nex/datastore/prepare_get_object.go @@ -6,9 +6,8 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - "github.com/PretendoNetwork/nintendo-badge-arcade-secure/utility" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) @@ -17,10 +16,13 @@ func PrepareGetObject(err error, client *nex.Client, callID uint32, dataStorePre dataVersion := database.GetVersionByDataID(uint32(dataStorePrepareGetParam.DataID)) - key := fmt.Sprintf("%s/%011d-%05d", os.Getenv("DATASTORE_DATA_PATH"), dataStorePrepareGetParam.DataID, dataVersion) - dataSize, _ := utility.S3ObjectSize(os.Getenv("S3_BUCKET_NAME"), key) + key := fmt.Sprintf("%s/%011d-%05d", os.Getenv("PN_NBA_CONFIG_S3_PATH"), dataStorePrepareGetParam.DataID, dataVersion) + dataSize, err := globals.S3ObjectSize(os.Getenv("PN_NBA_CONFIG_S3_BUCKET"), key) + if err != nil { + globals.Logger.Error(err.Error()) + } - pReqGetInfo.URL = fmt.Sprintf("http://%s.%s/%s", os.Getenv("S3_BUCKET_NAME"), os.Getenv("DATASTORE_DATA_URL"), key) + pReqGetInfo.URL = fmt.Sprintf("%s/%s", os.Getenv("PN_NBA_CONFIG_S3_ENDPOINT"), key) pReqGetInfo.RequestHeaders = []*datastore.DataStoreKeyValue{} pReqGetInfo.Size = uint32(dataSize) pReqGetInfo.RootCA = []byte{} diff --git a/nex/datastore/prepare_post_object.go b/nex/datastore/prepare_post_object.go index e1b4098..a76df18 100644 --- a/nex/datastore/prepare_post_object.go +++ b/nex/datastore/prepare_post_object.go @@ -3,12 +3,13 @@ package nex_datastore import ( "fmt" "os" + "time" + + "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-protocols-go/datastore" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/nex-protocols-go/datastore" ) func PreparePostObject(err error, client *nex.Client, callID uint32, param *datastore.DataStorePreparePostParam) { @@ -16,28 +17,60 @@ func PreparePostObject(err error, client *nex.Client, callID uint32, param *data var slot uint16 = 0 dataID := database.GetDataStorePersistenceInfo(pid, slot) - var initialVersion uint32 = 1 - pReqPostInfo := datastore.NewDataStoreReqPostInfo() + bucket := os.Getenv("PN_NBA_CONFIG_S3_BUCKET") + key := fmt.Sprintf("%s/%011d-%05d", os.Getenv("PN_NBA_CONFIG_S3_PATH"), dataID, 1) + + input := &globals.PostObjectInput{ + Bucket: bucket, + Key: key, + ExpiresIn: time.Minute * 15, + } - key := fmt.Sprintf("%s/%011d-%05d", os.Getenv("DATASTORE_DATA_PATH"), dataID, initialVersion) + res, _ := globals.S3PresignClient.PresignPostObject(input) fieldKey := datastore.NewDataStoreKeyValue() fieldKey.Key = "key" fieldKey.Value = key - fieldACL := datastore.NewDataStoreKeyValue() - fieldACL.Key = "acl" - fieldACL.Value = "private" + fieldCredential := datastore.NewDataStoreKeyValue() + fieldCredential.Key = "X-Amz-Credential" + fieldCredential.Value = res.Credential + + fieldSecurityToken := datastore.NewDataStoreKeyValue() + fieldSecurityToken.Key = "X-Amz-Security-Token" + fieldSecurityToken.Value = "" + + fieldAlgorithm := datastore.NewDataStoreKeyValue() + fieldAlgorithm.Key = "X-Amz-Algorithm" + fieldAlgorithm.Value = "AWS4-HMAC-SHA256" + + fieldDate := datastore.NewDataStoreKeyValue() + fieldDate.Key = "X-Amz-Date" + fieldDate.Value = res.Date + + fieldPolicy := datastore.NewDataStoreKeyValue() + fieldPolicy.Key = "policy" + fieldPolicy.Value = res.Policy fieldSignature := datastore.NewDataStoreKeyValue() - fieldSignature.Key = "signature" - fieldSignature.Value = "signature" // TODO + fieldSignature.Key = "X-Amz-Signature" + fieldSignature.Value = res.Signature + + pReqPostInfo := datastore.NewDataStoreReqPostInfo() pReqPostInfo.DataID = uint64(dataID) - pReqPostInfo.URL = fmt.Sprintf("http://%s.%s/", os.Getenv("S3_BUCKET_NAME"), os.Getenv("DATASTORE_DATA_URL")) + pReqPostInfo.URL = res.URL pReqPostInfo.RequestHeaders = []*datastore.DataStoreKeyValue{} - pReqPostInfo.FormFields = []*datastore.DataStoreKeyValue{fieldKey, fieldACL, fieldSignature} + pReqPostInfo.FormFields = []*datastore.DataStoreKeyValue{ + fieldKey, + fieldCredential, + fieldSecurityToken, + fieldAlgorithm, + fieldDate, + fieldPolicy, + fieldSignature, + } pReqPostInfo.RootCACert = []byte{} rmcResponseStream := nex.NewStreamOut(globals.NEXServer) diff --git a/nex/datastore/prepare_update_object.go b/nex/datastore/prepare_update_object.go index a36c905..f6f6ed2 100644 --- a/nex/datastore/prepare_update_object.go +++ b/nex/datastore/prepare_update_object.go @@ -3,38 +3,72 @@ package nex_datastore import ( "fmt" "os" + "time" + + "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-protocols-go/datastore" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/nex-protocols-go/datastore" ) func PrepareUpdateObject(err error, client *nex.Client, callID uint32, param *datastore.DataStorePrepareUpdateParam) { dataID := param.DataID dataVersion := database.GetVersionByDataID(uint32(dataID)) - pReqUpdateInfo := datastore.NewDataStoreReqUpdateInfo() + bucket := os.Getenv("PN_NBA_CONFIG_S3_BUCKET") + key := fmt.Sprintf("%s/%011d-%05d", os.Getenv("PN_NBA_CONFIG_S3_PATH"), dataID, dataVersion + 1) + + input := &globals.PostObjectInput{ + Bucket: bucket, + Key: key, + ExpiresIn: time.Minute * 15, + } - key := fmt.Sprintf("%s/%011d-%05d", os.Getenv("DATASTORE_DATA_PATH"), dataID, dataVersion+1) + res, _ := globals.S3PresignClient.PresignPostObject(input) fieldKey := datastore.NewDataStoreKeyValue() fieldKey.Key = "key" fieldKey.Value = key - fieldACL := datastore.NewDataStoreKeyValue() - fieldACL.Key = "acl" - fieldACL.Value = "private" + fieldCredential := datastore.NewDataStoreKeyValue() + fieldCredential.Key = "X-Amz-Credential" + fieldCredential.Value = res.Credential + + fieldSecurityToken := datastore.NewDataStoreKeyValue() + fieldSecurityToken.Key = "X-Amz-Security-Token" + fieldSecurityToken.Value = "" + + fieldAlgorithm := datastore.NewDataStoreKeyValue() + fieldAlgorithm.Key = "X-Amz-Algorithm" + fieldAlgorithm.Value = "AWS4-HMAC-SHA256" + + fieldDate := datastore.NewDataStoreKeyValue() + fieldDate.Key = "X-Amz-Date" + fieldDate.Value = res.Date + + fieldPolicy := datastore.NewDataStoreKeyValue() + fieldPolicy.Key = "policy" + fieldPolicy.Value = res.Policy fieldSignature := datastore.NewDataStoreKeyValue() - fieldSignature.Key = "signature" - fieldSignature.Value = "signature" // TODO + fieldSignature.Key = "X-Amz-Signature" + fieldSignature.Value = res.Signature + + pReqUpdateInfo := datastore.NewDataStoreReqUpdateInfo() pReqUpdateInfo.Version = dataVersion + 1 - pReqUpdateInfo.Url = fmt.Sprintf("http://%s.%s/", os.Getenv("S3_BUCKET_NAME"), os.Getenv("DATASTORE_DATA_URL")) + pReqUpdateInfo.Url = res.URL pReqUpdateInfo.RequestHeaders = []*datastore.DataStoreKeyValue{} - pReqUpdateInfo.FormFields = []*datastore.DataStoreKeyValue{fieldKey, fieldACL, fieldSignature} + pReqUpdateInfo.FormFields = []*datastore.DataStoreKeyValue{ + fieldKey, + fieldCredential, + fieldSecurityToken, + fieldAlgorithm, + fieldDate, + fieldPolicy, + fieldSignature, + } pReqUpdateInfo.RootCaCert = []byte{} rmcResponseStream := nex.NewStreamOut(globals.NEXServer) diff --git a/nex/secure-connection/nintendo-badge-arcade/get_maintenance_status.go b/nex/secure-connection/nintendo-badge-arcade/get_maintenance_status.go index 985a828..0c4f46d 100644 --- a/nex/secure-connection/nintendo-badge-arcade/get_maintenance_status.go +++ b/nex/secure-connection/nintendo-badge-arcade/get_maintenance_status.go @@ -4,7 +4,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" secure_connection_nintendo_badge_arcade "github.com/PretendoNetwork/nex-protocols-go/secure-connection/nintendo-badge-arcade" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" ) func GetMaintenanceStatus(err error, client *nex.Client, callID uint32) { diff --git a/nex/secure-connection/register.go b/nex/secure-connection/register.go index 632a93a..c367d10 100644 --- a/nex/secure-connection/register.go +++ b/nex/secure-connection/register.go @@ -7,7 +7,7 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" secure_connection "github.com/PretendoNetwork/nex-protocols-go/secure-connection" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" ) func Register(err error, client *nex.Client, callID uint32, stationUrls []*nex.StationURL) { diff --git a/nex/server.go b/nex/server.go index a2c1cf3..6a463b2 100644 --- a/nex/server.go +++ b/nex/server.go @@ -8,26 +8,10 @@ import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" "github.com/PretendoNetwork/nintendo-badge-arcade-secure/prudp" - nex "github.com/PretendoNetwork/nex-go" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/s3" + "github.com/PretendoNetwork/nex-go" ) func StartNEXServer() { - key := os.Getenv("S3_KEY") - secret := os.Getenv("S3_SECRET") - - s3Config := &aws.Config{ - Credentials: credentials.NewStaticCredentials(key, secret, ""), - Endpoint: aws.String("http://" + os.Getenv("DATASTORE_DATA_URL")), - Region: aws.String("us-east-1"), - } - - newSession, _ := session.NewSession(s3Config) - globals.S3Client = s3.New(newSession) - globals.NEXServer = nex.NewServer() globals.NEXServer.SetPRUDPVersion(1) globals.NEXServer.SetPRUDPProtocolMinorVersion(3) diff --git a/nex/shop/nintendo-badge-arcade/get_riv_token.go b/nex/shop/nintendo-badge-arcade/get_riv_token.go index a214870..06749c7 100644 --- a/nex/shop/nintendo-badge-arcade/get_riv_token.go +++ b/nex/shop/nintendo-badge-arcade/get_riv_token.go @@ -3,7 +3,7 @@ package nex_shop_nintendo_badge_arcade import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" nexproto "github.com/PretendoNetwork/nex-protocols-go/shop/nintendo-badge-arcade" ) diff --git a/nex/shop/nintendo-badge-arcade/post_play_log.go b/nex/shop/nintendo-badge-arcade/post_play_log.go index ae47c9b..68c1697 100644 --- a/nex/shop/nintendo-badge-arcade/post_play_log.go +++ b/nex/shop/nintendo-badge-arcade/post_play_log.go @@ -3,7 +3,7 @@ package nex_shop_nintendo_badge_arcade import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" nexproto "github.com/PretendoNetwork/nex-protocols-go/shop/nintendo-badge-arcade" ) diff --git a/utility/change_free_play_data_meta.go b/utility/change_free_play_data_meta.go index 13cb8d1..dea0ac5 100644 --- a/utility/change_free_play_data_meta.go +++ b/utility/change_free_play_data_meta.go @@ -2,7 +2,7 @@ package utility import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" ) func ChangeFreePlayDataMeta(dataID uint64, metaBinary []byte) { diff --git a/utility/datastore_post_param_to_free_play_data.go b/utility/datastore_post_param_to_free_play_data.go index 295d461..5154325 100644 --- a/utility/datastore_post_param_to_free_play_data.go +++ b/utility/datastore_post_param_to_free_play_data.go @@ -2,7 +2,7 @@ package utility import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/utility/free_play_data_to_datastore_meta_info.go b/utility/free_play_data_to_datastore_meta_info.go index 251502f..12b8b81 100644 --- a/utility/free_play_data_to_datastore_meta_info.go +++ b/utility/free_play_data_to_datastore_meta_info.go @@ -2,7 +2,7 @@ package utility import ( "github.com/PretendoNetwork/nintendo-badge-arcade-secure/database" - nex "github.com/PretendoNetwork/nex-go" + "github.com/PretendoNetwork/nex-go" "github.com/PretendoNetwork/nex-protocols-go/datastore" ) diff --git a/utility/s3_object_size.go b/utility/s3_object_size.go deleted file mode 100644 index 80e1943..0000000 --- a/utility/s3_object_size.go +++ /dev/null @@ -1,21 +0,0 @@ -package utility - -import ( - "github.com/PretendoNetwork/nintendo-badge-arcade-secure/globals" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3" -) - -func S3ObjectSize(bucket, key string) (uint64, error) { - headObj := s3.HeadObjectInput{ - Bucket: aws.String(bucket), - Key: aws.String(key), - } - - result, err := globals.S3Client.HeadObject(&headObj) - if err != nil { - return 0, err - } - - return uint64(aws.Int64Value(result.ContentLength)), nil -}