From 21f687f9cd361697892428f28d33b670b03c3802 Mon Sep 17 00:00:00 2001 From: elraphty Date: Mon, 4 Mar 2024 13:15:57 +0100 Subject: [PATCH 1/2] started presigned URL --- config/config.go | 44 ++++++++++++++++++++---------- go.mod | 66 +++++++++++++++++++++++++++++++++++++++++++-- go.sum | 50 ++++++++++++++++++++++++++++++++++ handlers/metrics.go | 12 ++++----- 4 files changed, 150 insertions(+), 22 deletions(-) diff --git a/config/config.go b/config/config.go index 36059cc8b..9b8a40ee7 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,7 @@ package config import ( + "context" "encoding/json" "fmt" "io" @@ -11,10 +12,9 @@ import ( "strings" "time" - "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/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/credentials" + "github.com/aws/aws-sdk-go-v2/service/s3" ) var Host string @@ -34,7 +34,8 @@ var S3Url string var AdminCheck string var AdminDevFreePass = "FREE_PASS" -var S3Client *s3.S3 +var S3Client *s3.Client +var PresignClient *s3.PresignClient func InitConfig() { Host = os.Getenv("LN_SERVER_BASE_URL") @@ -54,21 +55,36 @@ func InitConfig() { // Add to super admins SuperAdmins = StripSuperAdmins(AdminStrings) - awsConfig := aws.Config{ - Credentials: credentials.NewStaticCredentials(AwsAccess, AwsSecret, ""), - Region: aws.String(AwsRegion), - } - - awsSession, err := session.NewSessionWithOptions(session.Options{ - Config: awsConfig, - }) + awsConfig, err := config.LoadDefaultConfig(context.TODO(), + config.WithRegion(AwsRegion), + config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(AwsAccess, AwsSecret, "")), + ) if err != nil { fmt.Println("Could not setup AWS session", err) } // create a s3 client session - S3Client = s3.New(awsSession) + S3Client = s3.NewFromConfig(awsConfig) + + count := 10 + fmt.Printf("Let's list up to %v buckets for your account.\n", count) + result, err := S3Client.ListBuckets(context.TODO(), &s3.ListBucketsInput{}) + if err != nil { + fmt.Printf("Couldn't list buckets for your account. Here's why: %v\n", err) + return + } + if len(result.Buckets) == 0 { + fmt.Println("You don't have any buckets!") + } else { + if count > len(result.Buckets) { + count = len(result.Buckets) + } + for _, bucket := range result.Buckets[:count] { + fmt.Printf("\t%v\n", *bucket.Name) + } + } + PresignClient = s3.NewPresignClient(S3Client) // only make this call if there is a Relay auth key if RelayAuthKey != "" { diff --git a/go.mod b/go.mod index b89dc5c94..465d32cd0 100644 --- a/go.mod +++ b/go.mod @@ -3,39 +3,101 @@ module github.com/stakwork/sphinx-tribes go 1.2 require ( + github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect + github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect + github.com/ClickHouse/clickhouse-go v1.4.3 // indirect github.com/DATA-DOG/go-sqlmock v1.5.1 + github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ambelovsky/go-structs v1.1.0 + github.com/apache/arrow/go/arrow v0.0.0-20211013220434-5962184e7a30 // indirect github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de - github.com/aws/aws-sdk-go v1.49.16 // indirect + github.com/aws/aws-sdk-go-v2 v1.25.2 // indirect + github.com/aws/aws-sdk-go-v2/config v1.27.4 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.4 // indirect + github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.4 // indirect + github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1 // indirect + github.com/btcsuite/btcd v0.23.5-0.20230905170901-80f5a0ffdf36 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 + github.com/btcsuite/btcd/btcutil v1.1.4-0.20230904040416-d4f519f5dc05 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.3 + github.com/btcsuite/btcwallet v0.16.10-0.20230804184612-07be54bc22cf // indirect + github.com/cockroachdb/cockroach-go/v2 v2.1.1 // indirect + github.com/cznic/mathutil v0.0.0-20180504122225-ca4c9f2c1369 // indirect github.com/decred/dcrd/dcrec/secp256k1 v1.0.4 // indirect + github.com/dhui/dktest v0.3.16 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect github.com/fatih/structs v1.1.0 // indirect - github.com/fiatjaf/go-lnurl v1.13.1 + github.com/fiatjaf/go-lnurl v1.13.0 github.com/form3tech-oss/jwt-go v3.2.5+incompatible + github.com/fsnotify/fsnotify v1.5.4 // indirect + github.com/fsouza/fake-gcs-server v1.17.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.0 // indirect github.com/go-chi/chi v1.5.5 github.com/go-chi/jwtauth v1.2.0 github.com/go-co-op/gocron v1.37.0 github.com/go-playground/universal-translator v0.18.1 // indirect github.com/gobuffalo/packr/v2 v2.8.3 + github.com/gocql/gocql v0.0.0-20210515062232-b7ef815b4556 // indirect github.com/google/go-github/v39 v39.2.0 + github.com/gorilla/mux v1.7.4 // indirect github.com/gorilla/websocket v1.5.1 github.com/h2non/gock v1.2.0 + github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/imroc/req v0.3.2 github.com/jinzhu/gorm v1.9.16 github.com/joho/godotenv v1.5.1 + github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect + github.com/ktrysmt/go-bitbucket v0.6.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/lib/pq v1.10.9 + github.com/lightninglabs/neutrino v0.16.0 // indirect + github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f // indirect + github.com/lightningnetwork/lnd v0.16.4-beta.rc1 // indirect + github.com/lightningnetwork/lnd/cert v1.2.2 // indirect + github.com/lightningnetwork/lnd/clock v1.1.1 // indirect + github.com/lightningnetwork/lnd/healthcheck v1.2.3 // indirect + github.com/lightningnetwork/lnd/kvdb v1.4.4 // indirect + github.com/lightningnetwork/lnd/queue v1.1.1 // indirect + github.com/lightningnetwork/lnd/ticker v1.1.1 // indirect + github.com/lightningnetwork/lnd/tlv v1.1.1 // indirect + github.com/lightningnetwork/lnd/tor v1.1.2 // indirect + github.com/markbates/pkger v0.15.1 // indirect + github.com/microsoft/go-mssqldb v1.0.0 // indirect + github.com/moby/term v0.5.0 // indirect + github.com/mutecomm/go-sqlcipher/v4 v4.4.0 // indirect + github.com/nakagami/firebirdsql v0.0.0-20190310045651-3c02a58cfed8 // indirect github.com/nbd-wtf/ln-decodepay v1.11.1 + github.com/neo4j/neo4j-go-driver v1.8.1-0.20200803113522-b626aa943eba // indirect + github.com/onsi/gomega v1.26.0 // indirect + github.com/ory/dockertest/v3 v3.10.0 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible github.com/redis/go-redis/v9 v9.3.0 github.com/rs/cors v1.10.1 github.com/rs/xid v1.5.0 + github.com/snowflakedb/gosnowflake v1.6.3 // indirect github.com/stretchr/testify v1.8.4 + github.com/test-go/testify v1.1.4 // indirect github.com/tuan78/jsonconv v1.0.2 + github.com/xanzy/go-gitlab v0.15.0 // indirect + github.com/xdg-go/scram v1.1.1 // indirect + gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b // indirect + go.mongodb.org/mongo-driver v1.7.5 // indirect + golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 // indirect golang.org/x/oauth2 v0.15.0 google.golang.org/api v0.153.0 gopkg.in/go-playground/validator.v9 v9.31.0 // indirect gorm.io/driver/postgres v1.5.4 gorm.io/gorm v1.25.5 + modernc.org/b v1.0.0 // indirect + modernc.org/db v1.0.0 // indirect + modernc.org/file v1.0.0 // indirect + modernc.org/fileutil v1.0.0 // indirect + modernc.org/golex v1.0.0 // indirect + modernc.org/internal v1.0.0 // indirect + modernc.org/lldb v1.0.0 // indirect + modernc.org/ql v1.0.0 // indirect + modernc.org/sortutil v1.1.0 // indirect + modernc.org/zappy v1.0.0 // indirect ) diff --git a/go.sum b/go.sum index 743d29fef..bb54dfb8a 100644 --- a/go.sum +++ b/go.sum @@ -1212,30 +1212,66 @@ github.com/aws/aws-sdk-go v1.49.16 h1:KAQwhLg296hfffRdh+itA9p7Nx/3cXS/qOa3uF9ssi github.com/aws/aws-sdk-go v1.49.16/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/aws/aws-sdk-go-v2 v1.8.0/go.mod h1:xEFuWz+3TYdlPRuo+CqATbeDWIWyaT5uAPwPaWtgse0= github.com/aws/aws-sdk-go-v2 v1.9.2/go.mod h1:cK/D0BBs0b/oWPIcX/Z/obahJK1TT7IPVjy53i/mX/4= +github.com/aws/aws-sdk-go-v2 v1.25.2 h1:/uiG1avJRgLGiQM9X3qJM8+Qa6KRGK5rRPuXE0HUM+w= +github.com/aws/aws-sdk-go-v2 v1.25.2/go.mod h1:Evoc5AsmtveRt1komDwIsjHFyrP5tDuF1D1U+6z6pNo= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1/go.mod h1:sxpLb+nZk7tIfCWChfd+h4QwHNUR57d8hA1cleTkjJo= github.com/aws/aws-sdk-go-v2/config v1.6.0/go.mod h1:TNtBVmka80lRPk5+S9ZqVfFszOQAGJJ9KbT3EM3CHNU= github.com/aws/aws-sdk-go-v2/config v1.8.3/go.mod h1:4AEiLtAb8kLs7vgw2ZV3p2VZ1+hBavOc84hqxVNpCyw= +github.com/aws/aws-sdk-go-v2/config v1.27.4 h1:AhfWb5ZwimdsYTgP7Od8E9L1u4sKmDW2ZVeLcf2O42M= +github.com/aws/aws-sdk-go-v2/config v1.27.4/go.mod h1:zq2FFXK3A416kiukwpsd+rD4ny6JC7QSkp4QdN1Mp2g= github.com/aws/aws-sdk-go-v2/credentials v1.3.2/go.mod h1:PACKuTJdt6AlXvEq8rFI4eDmoqDFC5DpVKQbWysaDgM= github.com/aws/aws-sdk-go-v2/credentials v1.4.3/go.mod h1:FNNC6nQZQUuyhq5aE5c7ata8o9e4ECGmS4lAXC7o1mQ= +github.com/aws/aws-sdk-go-v2/credentials v1.17.4 h1:h5Vztbd8qLppiPwX+y0Q6WiwMZgpd9keKe2EAENgAuI= +github.com/aws/aws-sdk-go-v2/credentials v1.17.4/go.mod h1:+30tpwrkOgvkJL1rUZuRLoxcJwtI/OkeBLYnHxJtVe0= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0/go.mod h1:Mj/U8OpDbcVcoctrYwA2bak8k/HFPdcLzI/vaiXMwuM= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0/go.mod h1:gqlclDEZp4aqJOancXK6TN24aKhT0W0Ae9MHk3wzTMM= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2 h1:AK0J8iYBFeUk2Ax7O8YpLtFsfhdOByh2QIkHmigpRYk= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.2/go.mod h1:iRlGzMix0SExQEviAyptRWRGdYNo3+ufW/lCzvKVTUc= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.4.0/go.mod h1:eHwXu2+uE/T6gpnYWwBwqoeqRf9IXyCcolyOWDRAErQ= github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.4/go.mod h1:Ex7XQmbFmgFHrjUX6TN3mApKW5Hglyga+F7wZHTtYhA= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2 h1:bNo4LagzUKbjdxE0tIcR9pMzLR2U/Tgie1Hq1HQ3iH8= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.2/go.mod h1:wRQv0nN6v9wDXuWThpovGQjqF1HFdcgWjporw14lS8k= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2 h1:EtOU5jsPdIQNP+6Q2C5e3d65NKT1PeCiQk+9OdzO12Q= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.2/go.mod h1:tyF5sKccmDz0Bv4NrstEr+/9YkSPJHrcO7UsUKf7pWM= github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0/go.mod h1:Q5jATQc+f1MfZp3PDMhn6ry18hGvE0i8yvbXoKbnZaE= github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4/go.mod h1:ZcBrrI3zBKlhGFNYWvju0I3TR93I7YIgAfy82Fh4lcQ= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2 h1:en92G0Z7xlksoOylkUhuBSfJgijC7rHVLRdnIlHEs0E= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.2/go.mod h1:HgtQ/wN5G+8QSlK62lbOtNwQ3wTSByJ4wH2rCkPt+AE= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.2.2/go.mod h1:EASdTcM1lGhUe1/p4gkojHwlGJkeoRjjr1sRCzup3Is= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.3.0/go.mod h1:v8ygadNyATSm6elwJ/4gzJwcFhri9RqS8skgHKiwXPU= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.2 h1:zSdTXYLwuXDNPUS+V41i1SFDXG7V0ITp0D9UT9Cvl18= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.2/go.mod h1:v8m8k+qVy95nYi7d56uP1QImleIIY25BPiNJYzPBdFE= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.2/go.mod h1:NXmNI41bdEsJMrD0v9rUvbGCB5GwdBEpKvUvIY3vTFg= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.2/go.mod h1:72HRZDLMtmVQiLG2tLfQcaWLCssELvGl+Zf2WVxMmR8= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2 h1:5ffmXjPtwRExp1zc7gENLgCPyHFbhEPwVTkTiH9niSk= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.2/go.mod h1:Ru7vg1iQ7cR4i7SZ/JTLYN9kaXtbL69UdgG0OQWQxW0= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.5.2/go.mod h1:QuL2Ym8BkrLmN4lUofXYq6000/i5jPjosCNK//t6gak= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.7.2/go.mod h1:np7TMuJNT83O0oDOSF8i4dF3dvGqA6hPYYo6YYkzgRA= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.2 h1:1oY1AVEisRI4HNuFoLdRUB0hC63ylDAN6Me3MrfclEg= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.2/go.mod h1:KZ03VgvZwSjkT7fOetQ/wF3MZUvYFirlI1H5NklUNsY= github.com/aws/aws-sdk-go-v2/service/s3 v1.12.0/go.mod h1:6J++A5xpo7QDsIeSqPK4UHqMSyPOCopa+zKtqAMhqVQ= github.com/aws/aws-sdk-go-v2/service/s3 v1.16.1/go.mod h1:CQe/KvWV1AqRc65KqeJjrLzr5X2ijnFTTVzJW0VBRCI= +github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1 h1:juZ+uGargZOrQGNxkVHr9HHR/0N+Yu8uekQnV7EAVRs= +github.com/aws/aws-sdk-go-v2/service/s3 v1.51.1/go.mod h1:SoR0c7Jnq8Tpmt0KSLXIavhjmaagRqQpe9r70W3POJg= github.com/aws/aws-sdk-go-v2/service/sso v1.3.2/go.mod h1:J21I6kF+d/6XHVk7kp/cx9YVD2TMD2TbLwtRGVcinXo= github.com/aws/aws-sdk-go-v2/service/sso v1.4.2/go.mod h1:NBvT9R1MEF+Ud6ApJKM0G+IkPchKS7p7c2YPKwHmBOk= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.1 h1:utEGkfdQ4L6YW/ietH7111ZYglLJvS+sLriHJ1NBJEQ= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.1/go.mod h1:RsYqzYr2F2oPDdpy+PdhephuZxTfjHQe7SOBcZGoAU8= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1 h1:9/GylMS45hGGFCcMrUZDVayQE1jYSIN6da9jo7RAYIw= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.1/go.mod h1:YjAPFn4kGFqKC54VsHs5fn5B6d+PCY2tziEa3U/GB5Y= github.com/aws/aws-sdk-go-v2/service/sts v1.6.1/go.mod h1:hLZ/AnkIKHLuPGjEiyghNEdvJ2PP0MgOxcmv9EBJ4xs= github.com/aws/aws-sdk-go-v2/service/sts v1.7.2/go.mod h1:8EzeIqfWt2wWT4rJVu3f21TfrhJ8AEMzVybRNSb/b4g= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.1 h1:3I2cBEYgKhrWlwyZgfpSO2BpaMY1LHPqXYk/QGlu2ew= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.1/go.mod h1:uQ7YYKZt3adCRrdCBREm1CD3efFLOUNH77MrUCvx5oA= github.com/aws/smithy-go v1.7.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/aws/smithy-go v1.8.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw= +github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -1261,6 +1297,7 @@ github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZg github.com/btcsuite/btcd v0.23.1/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd v0.23.3/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd v0.23.4/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= +github.com/btcsuite/btcd v0.23.5-0.20230228185050-38331963bddd/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd v0.23.5-0.20230711222809-7faa9b266231/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= github.com/btcsuite/btcd v0.23.5-0.20230905170901-80f5a0ffdf36 h1:g/UbZ6iSzcUH9kEvC+rB8UBCqahmt69e8y6nCegczbg= github.com/btcsuite/btcd v0.23.5-0.20230905170901-80f5a0ffdf36/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= @@ -1289,6 +1326,7 @@ github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9 github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcwallet v0.15.1/go.mod h1:7OFsQ8ypiRwmr67hE0z98uXgJgXGAihE79jCib9x6ag= +github.com/btcsuite/btcwallet v0.16.10-0.20230621165747-9c21f464ce13/go.mod h1:Hl4PP/tSNcgN6himfx/020mYSa19a1qkqTuqQBUU97w= github.com/btcsuite/btcwallet v0.16.10-0.20230804184612-07be54bc22cf h1:iZrvu/dynDPUcLJFkKiN9wnS4EdjwZSJS1H33Rx/a1Y= github.com/btcsuite/btcwallet v0.16.10-0.20230804184612-07be54bc22cf/go.mod h1:qUPTONX2GVX7ERHvgh352/WySsfYlrkL4729qX9o9cA= github.com/btcsuite/btcwallet/wallet/txauthor v1.2.3/go.mod h1:T2xSiKGpUkSLCh68aF+FMXmKK9mFqNdHl9VaqOr+JjU= @@ -1458,6 +1496,8 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fergusstrange/embedded-postgres v1.10.0 h1:YnwF6xAQYmKLAXXrrRx4rHDLih47YJwVPvg8jeKfdNg= github.com/fergusstrange/embedded-postgres v1.10.0/go.mod h1:a008U8/Rws5FtIOTGYDYa7beVWsT3qVKyqExqYYjL+c= +github.com/fiatjaf/go-lnurl v1.13.0 h1:X9vQLMXMts9DBw3bzpvrnsKCShptHPe2C9FNh1eZWn4= +github.com/fiatjaf/go-lnurl v1.13.0/go.mod h1:yJJtz/AljThaJlJZCneDpSNr8aU72+Alf2z3s99gPF4= github.com/fiatjaf/go-lnurl v1.13.1 h1:7AeseawVNsl7JkZgAkTLf1mxAPbQuNrCPn3v7Qod0VQ= github.com/fiatjaf/go-lnurl v1.13.1/go.mod h1:GaZb1TFGKiMlmG7yphWg6pifLL2vJaRiDHAn3ZV9L9s= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= @@ -1975,6 +2015,7 @@ github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf h1:HZKvJUHlcXI/f/O0Avg7t8sqkPo78HFzjmeYFl6DPnc= github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf/go.mod h1:vxmQPeIQxPf6Jf9rM8R+B4rKBqLA2AjttNxkFBL2Plk= github.com/lightninglabs/neutrino v0.14.2/go.mod h1:OICUeTCn+4Tu27YRJIpWvvqySxx4oH4vgdP33Sw9RDc= +github.com/lightninglabs/neutrino v0.15.0/go.mod h1:pmjwElN/091TErtSE9Vd5W4hpxoG2/+xlb+HoPm9Gug= github.com/lightninglabs/neutrino v0.15.1-0.20230727175126-fc413d722789/go.mod h1:pmjwElN/091TErtSE9Vd5W4hpxoG2/+xlb+HoPm9Gug= github.com/lightninglabs/neutrino v0.16.0 h1:YNTQG32fPR/Zg0vvJVI65OBH8l3U18LSXXtX91hx0q0= github.com/lightninglabs/neutrino v0.16.0/go.mod h1:x3OmY2wsA18+Kc3TSV2QpSUewOCiscw2mKpXgZv2kZk= @@ -1983,12 +2024,16 @@ github.com/lightninglabs/neutrino/cache v1.1.1 h1:TllWOSlkABhpgbWJfzsrdUaDH2fBy/ github.com/lightninglabs/neutrino/cache v1.1.1/go.mod h1:XJNcgdOw1LQnanGjw8Vj44CvguYA25IMKjWFZczwZuo= github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display/go.mod h1:2oKOBU042GKFHrdbgGiKax4xVrFiZu51lhacUZQ9MnE= github.com/lightningnetwork/lightning-onion v1.0.2-0.20220211021909-bb84a1ccb0c5/go.mod h1:7dDx73ApjEZA0kcknI799m2O5kkpfg4/gr7N092ojNo= +github.com/lightningnetwork/lightning-onion v1.2.1-0.20221202012345-ca23184850a1/go.mod h1:7dDx73ApjEZA0kcknI799m2O5kkpfg4/gr7N092ojNo= github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f h1:Pua7+5TcFEJXIIZ1I2YAUapmbcttmLj4TTi786bIi3s= github.com/lightningnetwork/lightning-onion v1.2.1-0.20230823005744-06182b1d7d2f/go.mod h1:c0kvRShutpj3l6B9WtTsNTBUtjSmjZXbJd9ZBRQOSKI= github.com/lightningnetwork/lnd v0.15.0-beta/go.mod h1:Tm7LZrYeR2JQH1gEOKmd0NTCgjJ1Bnujkx4lcz9b5+A= +github.com/lightningnetwork/lnd v0.16.4-beta.rc1 h1:L8ktsv1lM5esVtiOlEtOBqU1dCoDckbm0FkcketBskQ= +github.com/lightningnetwork/lnd v0.16.4-beta.rc1/go.mod h1:sK9F98TpFuO/fjLCX4jEjc65qr2GZGs8IquVde1N46I= github.com/lightningnetwork/lnd v0.17.0-beta h1:Vzl2W3ClIDdffuQD5IaZwyP7CKR/CbXxWqws72Cq51g= github.com/lightningnetwork/lnd v0.17.0-beta/go.mod h1:8w27nArqZ1P7U6FP9U78GlaTLNm7u9GhV5Edv1C1yRU= github.com/lightningnetwork/lnd/cert v1.1.1/go.mod h1:1P46svkkd73oSoeI4zjkVKgZNwGq8bkGuPR8z+5vQUs= +github.com/lightningnetwork/lnd/cert v1.2.1/go.mod h1:04JhIEodoR6usBN5+XBRtLEEmEHsclLi0tEyxZQNP+w= github.com/lightningnetwork/lnd/cert v1.2.2/go.mod h1:jQmFn/Ez4zhDgq2hnYSw8r35bqGVxViXhX6Cd7HXM6U= github.com/lightningnetwork/lnd/clock v1.0.1/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg= github.com/lightningnetwork/lnd/clock v1.1.0/go.mod h1:KnQudQ6w0IAMZi1SgvecLZQZ43ra2vpDNj7H/aasemg= @@ -1999,6 +2044,7 @@ github.com/lightningnetwork/lnd/healthcheck v1.2.2/go.mod h1:IWY0GChlarRbXFkFDdE github.com/lightningnetwork/lnd/healthcheck v1.2.3 h1:oqhOOy8WmIEa6RBkYKC0mmYZkhl8T2kGD97n9jpML8o= github.com/lightningnetwork/lnd/healthcheck v1.2.3/go.mod h1:eDxH3dEwV9DeBW/6inrmlVh1qBOFV0AI14EEPnGt9gc= github.com/lightningnetwork/lnd/kvdb v1.3.1/go.mod h1:x+IpsuDynubjokUofavLXroeGfS/WrqUXXTK6vN/gp4= +github.com/lightningnetwork/lnd/kvdb v1.4.1/go.mod h1:f+F7Da8HTa8MePFsdWvusGRdcmWTgSWykGsVyC02Z5M= github.com/lightningnetwork/lnd/kvdb v1.4.4 h1:bCv63rVCvzqj1BkagN/EWTov6NDDgYEG/t0z2HepRMk= github.com/lightningnetwork/lnd/kvdb v1.4.4/go.mod h1:9SuaIqMA9ugrVkdvgQkYXa8CAKYNYd4vsEYORP4V698= github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms= @@ -2011,10 +2057,12 @@ github.com/lightningnetwork/lnd/ticker v1.1.1 h1:J/b6N2hibFtC7JLV77ULQp++QLtCwT6 github.com/lightningnetwork/lnd/ticker v1.1.1/go.mod h1:waPTRAAcwtu7Ji3+3k+u/xH5GHovTsCoSVpho0KDvdA= github.com/lightningnetwork/lnd/tlv v1.0.2/go.mod h1:fICAfsqk1IOsC1J7G9IdsWX1EqWRMqEDCNxZJSKr9C4= github.com/lightningnetwork/lnd/tlv v1.0.3/go.mod h1:dzR/aZetBri+ZY/fHbwV06fNn/3UID6htQzbHfREFdo= +github.com/lightningnetwork/lnd/tlv v1.1.0/go.mod h1:0+JKp4un47MG1lnj6jKa8woNeB1X7w3yF4MZB1NHiiE= github.com/lightningnetwork/lnd/tlv v1.1.1 h1:BW1u9+uHLRA9sm+8FBkAg1H9rPjrj3S9KvXYiCYjQWk= github.com/lightningnetwork/lnd/tlv v1.1.1/go.mod h1:292dSXpZ+BNnSJFjS1qvHden9LEbulmECglSgfg+4lw= github.com/lightningnetwork/lnd/tor v1.0.0/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64= github.com/lightningnetwork/lnd/tor v1.0.1/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64= +github.com/lightningnetwork/lnd/tor v1.1.0/go.mod h1:RDtaAdwfAm+ONuPYwUhNIH1RAvKPv+75lHPOegUcz64= github.com/lightningnetwork/lnd/tor v1.1.2 h1:3zv9z/EivNFaMF89v3ciBjCS7kvCj4ZFG7XvD2Qq0/k= github.com/lightningnetwork/lnd/tor v1.1.2/go.mod h1:j7T9uJ2NLMaHwE7GiBGnpYLn4f7NRoTM6qj+ul6/ycA= github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw= @@ -2103,6 +2151,7 @@ github.com/mutecomm/go-sqlcipher/v4 v4.4.0/go.mod h1:PyN04SaWalavxRGH9E8ZftG6Ju7 github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nakagami/firebirdsql v0.0.0-20190310045651-3c02a58cfed8/go.mod h1:86wM1zFnC6/uDBfZGNwB65O+pR2OFi5q/YQaEUid1qA= +github.com/nbd-wtf/ln-decodepay v1.5.1/go.mod h1:xzBXPaCj/7oRRaui+iYSIxy5LYUjoPfAyAGq2WCyNKk= github.com/nbd-wtf/ln-decodepay v1.6.0/go.mod h1:ZY0ZeLImteHHe9Uub75c+V23L0EMNYnBX0lnEAI0KWM= github.com/nbd-wtf/ln-decodepay v1.11.1 h1:MPiT4a4qZ2cKY27Aj0dI8sLFrLz5Ycu72Z3EG1HfPjk= github.com/nbd-wtf/ln-decodepay v1.11.1/go.mod h1:xzBXPaCj/7oRRaui+iYSIxy5LYUjoPfAyAGq2WCyNKk= @@ -2507,6 +2556,7 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20220426173459-3bcf042a4bf5/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/exp v0.0.0-20221111094246-ab4555d3164f/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0 h1:pVgRXcIictcr+lBQIFeiwuwtDIs4eL21OuM9nyAADmo= golang.org/x/exp v0.0.0-20230315142452-642cacee5cc0/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= diff --git a/handlers/metrics.go b/handlers/metrics.go index e5b91d87e..54bf37033 100644 --- a/handlers/metrics.go +++ b/handlers/metrics.go @@ -2,6 +2,7 @@ package handlers import ( "bytes" + "context" "encoding/csv" "encoding/json" "fmt" @@ -12,8 +13,8 @@ import ( "path" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/fatih/structs" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/config" @@ -379,20 +380,19 @@ func UploadMetricsCsv(data [][]string, request db.PaymentDateRange) (error, stri key := fmt.Sprintf("metrics%s-%s.csv", request.StartDate, request.EndDate) path := fmt.Sprintf("%s/%s", config.S3FolderName, key) - _, err = config.S3Client.PutObject(&s3.PutObjectInput{ + _, err = config.S3Client.PutObject(context.Background(), &s3.PutObjectInput{ Bucket: aws.String(config.S3BucketName), Key: aws.String(path), Body: bytes.NewReader(fileBuffer), ContentLength: aws.Int64(fileSize), ContentType: aws.String("application/csv"), ContentDisposition: aws.String("attachment"), - ServerSideEncryption: aws.String("AES256"), + ServerSideEncryption: "AES256", }) - url := fmt.Sprintf("%s/%s/%s", config.S3Url, config.S3FolderName, key) - // Delete image from uploads folder DeleteFileFromUploadsFolder(filePath) + url := fmt.Sprintf("%s/%s/%s", config.S3Url, config.S3FolderName, key) return err, url } From 86d5e2b1f30a647ef7893611bd1a572ad77fb981 Mon Sep 17 00:00:00 2001 From: elraphty Date: Mon, 4 Mar 2024 19:56:13 +0100 Subject: [PATCH 2/2] finished Presigned URLs --- config/config.go | 18 ------------- db/metrics.go | 2 +- handlers/metrics.go | 65 +++++++++++++++++++++++++++++++++++++-------- 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/config/config.go b/config/config.go index 9b8a40ee7..520cfb5b0 100644 --- a/config/config.go +++ b/config/config.go @@ -66,24 +66,6 @@ func InitConfig() { // create a s3 client session S3Client = s3.NewFromConfig(awsConfig) - - count := 10 - fmt.Printf("Let's list up to %v buckets for your account.\n", count) - result, err := S3Client.ListBuckets(context.TODO(), &s3.ListBucketsInput{}) - if err != nil { - fmt.Printf("Couldn't list buckets for your account. Here's why: %v\n", err) - return - } - if len(result.Buckets) == 0 { - fmt.Println("You don't have any buckets!") - } else { - if count > len(result.Buckets) { - count = len(result.Buckets) - } - for _, bucket := range result.Buckets[:count] { - fmt.Printf("\t%v\n", *bucket.Name) - } - } PresignClient = s3.NewPresignClient(S3Client) // only make this call if there is a Relay auth key diff --git a/db/metrics.go b/db/metrics.go index 9a33bdbbe..5ec74bb48 100644 --- a/db/metrics.go +++ b/db/metrics.go @@ -190,7 +190,7 @@ func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request) } else { orderQuery = " ORDER BY " + sortBy + "" + "DESC" } - if limit > 0 { + if limit > 1 { limitQuery = fmt.Sprintf("LIMIT %d OFFSET %d", limit, offset) } diff --git a/handlers/metrics.go b/handlers/metrics.go index 54bf37033..88cc3a218 100644 --- a/handlers/metrics.go +++ b/handlers/metrics.go @@ -380,19 +380,62 @@ func UploadMetricsCsv(data [][]string, request db.PaymentDateRange) (error, stri key := fmt.Sprintf("metrics%s-%s.csv", request.StartDate, request.EndDate) path := fmt.Sprintf("%s/%s", config.S3FolderName, key) - _, err = config.S3Client.PutObject(context.Background(), &s3.PutObjectInput{ - Bucket: aws.String(config.S3BucketName), - Key: aws.String(path), - Body: bytes.NewReader(fileBuffer), - ContentLength: aws.Int64(fileSize), - ContentType: aws.String("application/csv"), - ContentDisposition: aws.String("attachment"), - ServerSideEncryption: "AES256", - }) + + err, postPresignedUrl := createPresignedUrl(path) + + if err != nil { + fmt.Println("Presigned Error", err) + } + + r, err := http.NewRequest(http.MethodPut, postPresignedUrl, bytes.NewReader(fileBuffer)) + if err != nil { + fmt.Println("Posting presign s3 error:", err) + } + r.Header.Set("Content-Type", "multipart/form-data") + client := &http.Client{} + _, err = client.Do(r) + + if err != nil { + fmt.Println("Error occured while posting presigned URL", err) + } // Delete image from uploads folder DeleteFileFromUploadsFolder(filePath) - url := fmt.Sprintf("%s/%s/%s", config.S3Url, config.S3FolderName, key) - return err, url + err, presignedUrlGet := getPresignedUrl(path) + + return err, presignedUrlGet +} + +func createPresignedUrl(path string) (error, string) { + presignedUrl, err := config.PresignClient.PresignPutObject(context.Background(), + &s3.PutObjectInput{ + Bucket: aws.String(config.S3BucketName), + Key: aws.String(path), + }, + s3.WithPresignExpires(time.Minute*15), + ) + + if err != nil { + return err, "" + } + + return nil, presignedUrl.URL +} + +func getPresignedUrl(path string) (error, string) { + presignedUrl, err := config.PresignClient.PresignGetObject(context.Background(), + &s3.GetObjectInput{ + Bucket: aws.String(config.S3BucketName), + Key: aws.String(path), + ResponseContentDisposition: aws.String("attachment"), + }, + s3.WithPresignExpires(time.Minute*15), + ) + + if err != nil { + return err, "" + } + + return nil, presignedUrl.URL }