Compare commits

..

19 Commits
v0.0.2 ... main

Author SHA1 Message Date
7281b9b678 add new option "-v"
All checks were successful
Release Version / build (push) Successful in 5m25s
2024-09-29 13:40:49 +02:00
cdaf3d081e Merge branch 'main' of https://git.fluffy.pw/leafus/s3-client
All checks were successful
Release Version / build (push) Successful in 5m30s
2024-09-29 13:28:08 +02:00
425cf609cc Add -overwrite function 2024-09-29 13:28:06 +02:00
8bde3ccb90 Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 5m33s
2024-09-29 13:02:55 +02:00
915245e9da Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 8s
2024-09-29 13:01:03 +02:00
20c9b45561 Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 7s
2024-09-29 13:00:48 +02:00
5c518abcdc Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 8s
2024-09-29 13:00:21 +02:00
431787d061 Update main.go
All checks were successful
Release Version / build (push) Successful in 6s
2024-09-29 12:59:14 +02:00
a9f0f3cbbc fix Mac OS target
All checks were successful
Release Version / build (push) Successful in 7s
2024-09-29 12:58:52 +02:00
563b11fd33 Merge branch 'main' of https://git.fluffy.pw/leafus/s3-client
All checks were successful
Release Version / build (push) Successful in 7s
2024-09-29 12:56:37 +02:00
a18fe3c1e6 add Mac OS target
All checks were successful
Release Version / build (push) Successful in 9s
2024-09-29 12:55:58 +02:00
87df3b82d5 Add file not existent handling 2024-09-29 12:54:56 +02:00
05240851aa add new targets
All checks were successful
Release Version / build (push) Successful in 8s
2024-09-29 12:45:59 +02:00
e72a7a7468 Merge branch 'main' of https://git.fluffy.pw/leafus/s3-client
All checks were successful
Release Version / build (push) Successful in 6s
2024-09-29 05:11:32 +02:00
d8049b0e00 Change README.md 2024-09-29 05:11:30 +02:00
5e68824953 Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 7s
2024-09-29 05:08:54 +02:00
7eb9f7ce4a Update .gitea/workflows/build.yaml
All checks were successful
Release Version / build (push) Successful in 8s
2024-09-29 05:07:22 +02:00
55bc83b82b Merge branch 'main' of https://git.fluffy.pw/leafus/s3-client
All checks were successful
Release Version / build (push) Successful in 1m17s
2024-09-29 04:59:20 +02:00
156d1a3e23 Add file deletion and ignore s3-client-dev 2024-09-29 04:58:53 +02:00
6 changed files with 163 additions and 10 deletions

View File

@ -23,10 +23,50 @@ jobs:
go mod tidy
go build -o s3-client_linux.x86_64
- name: Build Go binary for Linux (x86)
run: |
go mod tidy
GOARCH=386 go build -o s3-client_linux.x86
- name: Build Go binary for Linux (ARM64)
run: |
go mod tidy
GOARCH=arm64 go build -o s3-client_linux.arm64
- name: Build Go binary for Mac OS (x86_64)
run: |
go mod tidy
GOOS=darwin GOARCH=amd64 go build -o s3-client_darwin.x86_64.app
- name: Build Go binary for Mac OS (ARM64)
run: |
go mod tidy
GOOS=darwin GOARCH=arm64 go build -o s3-client_darwin.arm64.app
- name: Build Go binary for Linux (ARMv7)
run: |
go mod tidy
GOARCH=arm go build -o s3-client_linux.armv7
- name: Build Go binary for Linux (RISC-V)
run: |
go mod tidy
GOARCH=riscv64 go build -o s3-client_linux.riscv64
- name: Build Go binary for Windows
run: |
GOOS=windows GOARCH=amd64 go build -o s3-client_windows.x86_64.exe
- name: Build Go binary for Windows (x86)
run: |
go mod tidy
GOOS=windows GOARCH=386 go build -o s3-client_windows.x86.exe
- name: Build Go binary for Windows (ARM64)
run: |
go mod tidy
GOOS=windows GOARCH=arm64 go build -o s3-client_windows.arm64.exe
- name: Get latest commit ID
id: get_commit
run: |
@ -36,6 +76,11 @@ jobs:
- name: Get latest version and increment
id: create_version
run: |
if [ "${{ env.main_go_modified }}" = "false" ]; then
echo "No changes in main.go, skipping version increment and release creation."
exit 0
fi
git fetch --tags
latest_version=$(git tag | sort -V | tail -n 1 || echo "v0.0.0")
@ -77,7 +122,16 @@ jobs:
with:
files: |
./s3-client_linux.x86_64
./s3-client_linux.x86
./s3-client_linux.armv7
./s3-client_linux.arm64
./s3-client_linux.riscv64
./s3-client_windows.x86_64.exe
./s3-client_windows.x86.exe
./s3-client_windows.arm64.exe
./s3-client_darwin.x86_64.app
./s3-client_darwin.arm64.app
tag_name: ${{ env.new_version }}
name: Release ${{ env.new_version }}
body: |

1
.gitignore vendored
View File

@ -1 +1,2 @@
s3config.toml
s3-client-dev

View File

@ -42,13 +42,23 @@ returnurl = "your_return_url"
### Upload a file
```
./s3-client -file "path/to/your/file" [optional] -directory "/exampledir"
./s3-client_linux.x86_64 -file "path/to/your/file" [optional] -directory "/exampledir"
```
### List files
```
./s3-client -list
./s3-client_linux.x86_64 -list
```
### Delete files
```
./s3-client_linux.x86_64 -delete "filename.png"
or with an directory
./s3-client_linux.x86_64 -delete "/dir1/filename.png"
```
### Help message

10
go.mod
View File

@ -12,11 +12,12 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
@ -28,7 +29,8 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect

12
go.sum
View File

@ -22,8 +22,14 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
@ -31,6 +37,8 @@ github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
@ -66,6 +74,10 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

80
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"bufio"
"flag"
"fmt"
"os"
@ -20,8 +21,22 @@ func main() {
configPath := flag.String("config", "", "Path to the configuration file")
directory := flag.String("directory", "", "Directory in the S3 bucket to upload the file to")
listFiles := flag.Bool("list", false, "List files in the S3 bucket")
deleteFile := flag.String("delete", "", "Path to the file to delete from the S3 bucket")
overwrite := flag.Bool("overwrite", false, "Overwrite the file if it already exists on S3")
verbose := flag.Bool("v", false, "Enable verbose output")
flag.Parse()
if *verbose {
fmt.Println("Debug Information:")
fmt.Printf("File Path: %s\n", *filePath)
fmt.Printf("Force Path Style: %t\n", *forcePathStyle)
fmt.Printf("Config Path: %s\n", *configPath)
fmt.Printf("Directory: %s\n", *directory)
fmt.Printf("List Files: %t\n", *listFiles)
fmt.Printf("Delete File: %s\n", *deleteFile)
fmt.Printf("Overwrite: %t\n", *overwrite)
}
if *configPath == "" {
homeDir, err := os.UserHomeDir()
if err != nil {
@ -42,7 +57,7 @@ func main() {
}
if *configPath == "" {
fmt.Println("No config file found. Please specify a config file using --config or create one in the default locations.")
fmt.Println("No config file found. Please specify a config file using -config or create one in the default locations.")
os.Exit(1)
}
}
@ -80,12 +95,22 @@ func main() {
return
}
if *deleteFile != "" {
deleteS3File(svc, bucket, *deleteFile)
return
}
if *filePath == "" {
fmt.Println("No file specified for upload. Use -file to specify a file or -list to list bucket contents.")
fmt.Println("Use -help for more information")
os.Exit(1)
}
if _, err := os.Stat(*filePath); os.IsNotExist(err) {
fmt.Printf("File does not exist: %s\n", *filePath)
os.Exit(1)
}
file, err := os.Open(*filePath)
if err != nil {
fmt.Printf("Error opening file: %s\n", err)
@ -102,17 +127,41 @@ func main() {
}
key = filepath.ToSlash(key)
_, err = svc.PutObject(&s3.PutObjectInput{
headObjectInput := &s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
}
_, err = svc.HeadObject(headObjectInput)
if err == nil && !*overwrite {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("The file with the same filename already exists on S3. Do you want to overwrite? [y/n] > ")
response, _ := reader.ReadString('\n')
response = strings.TrimSpace(response)
if strings.ToLower(response) != "y" {
fmt.Println("Upload cancelled.")
os.Exit(0)
}
}
putObjectInput := &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
Body: file,
})
}
req, _ := svc.PutObjectRequest(putObjectInput)
err = req.Send()
if err != nil {
fmt.Printf("Error uploading file to S3: %s\n", err)
os.Exit(1)
}
if *verbose {
fmt.Printf("Uploaded file: %s\n", *filePath)
fmt.Printf("Endpoint: %s\n", endpoint)
fmt.Printf("HTTP Status Code: %d\n", req.HTTPResponse.StatusCode)
}
fullURL := fmt.Sprintf("%s/%s",
strings.TrimRight(returnurl, "/"),
strings.TrimLeft(key, "/"))
@ -141,3 +190,28 @@ func listBucketFiles(svc *s3.S3, bucket string) {
os.Exit(1)
}
}
func deleteS3File(svc *s3.S3, bucket, filePath string) {
filePath = strings.TrimPrefix(filePath, "/")
_, err := svc.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(filePath),
})
if err != nil {
fmt.Printf("Error deleting file from S3: %s\n", err)
os.Exit(1)
}
err = svc.WaitUntilObjectNotExists(&s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(filePath),
})
if err != nil {
fmt.Printf("Error waiting for file deletion: %s\n", err)
os.Exit(1)
}
fmt.Printf("Successfully deleted file: %s\n", filePath)
}