Skip to content

Commit

Permalink
can generate some S3 link for downloading the client
Browse files Browse the repository at this point in the history
  • Loading branch information
eltorio committed Mar 24, 2024
1 parent e55d188 commit 6a41f09
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 1 deletion.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,31 @@ app:
cryptkey: 123123123123 # password encryption salt value, recommended not to change after the first modification
```
### S3 Client Download
by adding the following configuration to the configuration file, you can download obtain dynamically from the S3 server a download link for the RustDesk client:
```yaml
s3:
Endpoint: https://random.objectstorage.eu-par-1.oraclecloud.com
Region: eu-par-1
AccessKey: 2b3e1f4a5c6d7e8f9a0b1c2d3e4f5g6h7i8j9k0l
SecretKey: R5sT8uVwX1yZ2aB3cD4eF5gH6iJ7kL8mN9oP0qR1s
Bucket: randombucket123
Windows64Key: master/sctgdesk-releases/sctgdesk-2.0.1-x86_64.exe
Windows32Key: master/sctgdesk-releases/sctgdesk-2.0.1-i686.exe
OSXKey: master/sctgdesk-releases/sctgdesk-2.0.1.dmg
OSXArm64Key: master/sctgdesk-releases/sctgdesk-2.0.1.dmg
```
The api endpoint for the download link is `/api/software/client-download-link/os` where `os` can be `windows64`, `windows32`, `osx` or `osxarm64`.
the api will return a json object with the download link for the client. Links are valid for 15 minutes.

```json
{
"url": "https://random.objectstorage.eu-par-1.oraclecloud.com/master/sctgdesk-2.0.1.dmg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=949a57ffdc586d72961ccab7618b9d58a7372d40%2F20240324%2Feu-marseille-1%2Fs3%2Faws4_request&X-Amz-Date=20240324T175308Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&x-id=GetObject&X-Amz-Signature=43cebc953df3f9cc1ed8ba51191956f0e3ade9db27684107cbad8c9c9605394b"
}
```

### Set Up and Run

1. Run the program
Expand Down
84 changes: 84 additions & 0 deletions app/controllers/software.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package controllers

import (
"rustdesk-api-server/utils/beegoHelper"

"context"

"rustdesk-api-server/global"

"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/beego/beego/v2/server/web"
)

type SoftwareController struct {
web.Controller
}

// Get software information
func (ctl *SoftwareController) GetSoftwareInfo() {
ctl.Ctx.Output.JSON(beegoHelper.H{
"software": "SCTGDesk",
"version": "1.2.4",
"website": "https://github.com/sctg-development/sctgdesk",
}, true, false)

}

func getSignedReleaseUrl(bucket string, key string) (string, error) {
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(global.ConfigVar.S3.Region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(global.ConfigVar.S3.AccessKey, global.ConfigVar.S3.SecretKey, "")),
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{URL: global.ConfigVar.S3.Endpoint}, nil
})))

if err != nil {
return "", err
}
client := s3.NewFromConfig(cfg)
presignClient := s3.NewPresignClient(client)

resp, err := presignClient.PresignGetObject(context.TODO(), &s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}, func(options *s3.PresignOptions) {})
return resp.URL, err
}

// Get Windows client download link
func (ctl *SoftwareController) GetClientDownloadLink(key string) {

url, err := getSignedReleaseUrl(global.ConfigVar.S3.Bucket, key)

if err != nil {
ctl.Ctx.Output.JSON(beegoHelper.H{
"msg": "Failed to generate download link",
"err": err.Error(),
}, true, false)
return
}
ctl.Ctx.Output.JSON(beegoHelper.H{
"url": url,
}, true, false)
}

func (ctl *SoftwareController) GetClientDownloadLinkW64() {
ctl.GetClientDownloadLink(global.ConfigVar.S3.Windows64Key)
}

func (ctl *SoftwareController) GetClientDownloadLinkW32() {
ctl.GetClientDownloadLink(global.ConfigVar.S3.Windows32Key)
}

func (ctl *SoftwareController) GetClientDownloadLinkOSX() {
ctl.GetClientDownloadLink(global.ConfigVar.S3.OSXKey)
}

func (ctl *SoftwareController) GetClientDownloadLinkOSXArm64() {
ctl.GetClientDownloadLink(global.ConfigVar.S3.OSXArm64Key)
}
13 changes: 13 additions & 0 deletions global/confDto/s3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package confDto

type S3Config struct {
Region string
Endpoint string
AccessKey string
SecretKey string
Bucket string
Windows64Key string
Windows32Key string
OSXKey string
OSXArm64Key string
}
1 change: 1 addition & 0 deletions global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type Config struct {
DBType string `json:"dbtype"`
Mysql confDto.Mysql `json:"mysql"`
App confDto.AppConfig `json:"app"`
S3 confDto.S3Config `json:"s3"`
}
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,29 @@ require (
github.com/spf13/viper v1.18.2
)

require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.4 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5 // indirect
github.com/aws/smithy-go v1.20.1 // indirect
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.0
github.com/aws/aws-sdk-go-v2/config v1.27.9
github.com/aws/aws-sdk-go-v2/credentials v1.17.9
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.0
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
Expand Down
36 changes: 36 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/aws/aws-sdk-go-v2 v1.26.0 h1:/Ce4OCiM3EkpW7Y+xUnfAFpchU78K7/Ug01sZni9PgA=
github.com/aws/aws-sdk-go-v2 v1.26.0/go.mod h1:35hUlJVYd+M++iLI3ALmVwMOyRYMmRqUXpTtRGW+K9I=
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.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg=
github.com/aws/aws-sdk-go-v2/config v1.27.9/go.mod h1:dK1FQfpwpql83kbD873E9vz4FyAxuJtR22wzoXn3qq0=
github.com/aws/aws-sdk-go-v2/credentials v1.17.9 h1:N8s0/7yW+h8qR8WaRlPQeJ6czVMNQVNtNdUqf6cItao=
github.com/aws/aws-sdk-go-v2/credentials v1.17.9/go.mod h1:446YhIdmSV0Jf/SLafGZalQo+xr2iw7/fzXGDPTU1yQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 h1:af5YzcLf80tv4Em4jWVD75lpnOHSBkPUZxZfGkrI3HI=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0/go.mod h1:nQ3how7DMnFMWiU1SpECohgC82fpn4cKZ875NDMmwtA=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.4 h1:0ScVK/4qZ8CIW0k8jOeFVsyS/sAiXpYxRBLolMkuLQM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.4/go.mod h1:84KyjNZdHC6QZW08nfHI6yZgPd+qRgaWcYsyLUo3QY8=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.4 h1:sHmMWWX5E7guWEFQ9SVo6A3S4xpPrWnd77a6y4WM6PU=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.4/go.mod h1:WjpDrhWisWOIoS9n3nk67A3Ll1vfULJ9Kq6h29HTD48=
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.4 h1:SIkD6T4zGQ+1YIit22wi37CGNkrE7mXV1vNA5VpI3TI=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.4/go.mod h1:XfeqbsG0HNedNs0GT+ju4Bs+pFAwsrlzcRdMvdNVf5s=
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.6 h1:NkHCgg0Ck86c5PTOzBZ0JRccI51suJDg5lgFtxBu1ek=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.6/go.mod h1:mjTpxjC8v4SeINTngrnKFgm2QUi+Jm+etTbCxh8W4uU=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 h1:b+E7zIUHMmcB4Dckjpkapoy47W6C9QBv/zoUP+Hn8Kc=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6/go.mod h1:S2fNV0rxrP78NhPbCZeQgY8H9jdDMeGtwcfZIRxzBqU=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.4 h1:uDj2K47EM1reAYU9jVlQ1M5YENI1u6a/TxJpf6AeOLA=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.4/go.mod h1:XKCODf4RKHppc96c2EZBGV/oCUC7OClxAo2MEyg4pIk=
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.0 h1:r3o2YsgW9zRcIP3Q0WCmttFVhTuugeKIvT5z9xDspc0=
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.0/go.mod h1:w2E4f8PUfNtyjfL6Iu+mWI96FGttE03z3UdNcUEC4tA=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3 h1:mnbuWHOcM70/OFUlZZ5rcdfA8PflGXXiefU/O+1S3+8=
github.com/aws/aws-sdk-go-v2/service/sso v1.20.3/go.mod h1:5HFu51Elk+4oRBZVxmHrSds5jFXmFj8C3w7DVF2gnrs=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 h1:uLq0BKatTmDzWa/Nu4WO0M1AaQDaPpwTKAeByEc6WFM=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3/go.mod h1:b+qdhjnxj8GSR6t5YfphOffeoQSQ1KmpoVVuBn+PWxs=
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5 h1:J/PpTf/hllOjx8Xu9DMflff3FajfLxqM5+tepvVXmxg=
github.com/aws/aws-sdk-go-v2/service/sts v1.28.5/go.mod h1:0ih0Z83YDH/QeQ6Ori2yGE2XvWYv/Xm+cZc01LC6oK0=
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/beego/beego/v2 v2.1.6 h1:ny2WqvtpG1gAkEqJ9PQrOz6ZcQvVBJK+dECDOd/heIM=
github.com/beego/beego/v2 v2.1.6/go.mod h1:kFJvA21OjBwixXKx7BeH+Ug492Pp+h4cORHFTf1L8e0=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
6 changes: 5 additions & 1 deletion routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func init() {
beego.Router("/api/set-pwd", &controllers.UserController{}, "get:SetPwd")
beego.Router("/api/users", &controllers.UserController{}, "get:Users")
beego.Router("/api/peers", &controllers.UserController{}, "get:Peers")

beego.Router("/api/software/info", &controllers.SoftwareController{}, "get:GetSoftwareInfo")
beego.Router("/api/software/client-download-link/w64", &controllers.SoftwareController{}, "get:GetClientDownloadLinkW64")
beego.Router("/api/software/client-download-link/w32", &controllers.SoftwareController{}, "get:GetClientDownloadLinkW32")
beego.Router("/api/software/client-download-link/osx", &controllers.SoftwareController{}, "get:GetClientDownloadLinkOSX")
beego.Router("/api/software/client-download-link/osxarm64", &controllers.SoftwareController{}, "get:GetClientDownloadLinkOSXArm64")
// Set up an error route
beego.ErrorController(&controllers.ErrorController{})
}

0 comments on commit 6a41f09

Please sign in to comment.