Compare commits
No commits in common. "main" and "v0.0.2" have entirely different histories.
|
@ -23,50 +23,10 @@ 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: |
|
||||
|
@ -76,11 +36,6 @@ 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")
|
||||
|
@ -122,16 +77,7 @@ 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
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
s3config.toml
|
||||
s3-client-dev
|
14
README.md
14
README.md
|
@ -42,23 +42,13 @@ returnurl = "your_return_url"
|
|||
### Upload a file
|
||||
|
||||
```
|
||||
./s3-client_linux.x86_64 -file "path/to/your/file" [optional] -directory "/exampledir"
|
||||
./s3-client -file "path/to/your/file" [optional] -directory "/exampledir"
|
||||
```
|
||||
|
||||
### List files
|
||||
|
||||
```
|
||||
./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"
|
||||
./s3-client -list
|
||||
```
|
||||
|
||||
### Help message
|
||||
|
|
10
go.mod
10
go.mod
|
@ -12,12 +12,11 @@ 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.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.16 // indirect
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // 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
|
||||
|
@ -29,8 +28,7 @@ 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.25.0 // indirect
|
||||
golang.org/x/term v0.24.0 // indirect
|
||||
golang.org/x/sys v0.18.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
12
go.sum
|
@ -22,14 +22,8 @@ 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=
|
||||
|
@ -37,8 +31,6 @@ 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=
|
||||
|
@ -74,10 +66,6 @@ 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
80
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -21,22 +20,8 @@ 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 {
|
||||
|
@ -57,7 +42,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)
|
||||
}
|
||||
}
|
||||
|
@ -95,22 +80,12 @@ 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)
|
||||
|
@ -127,41 +102,17 @@ func main() {
|
|||
}
|
||||
key = filepath.ToSlash(key)
|
||||
|
||||
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{
|
||||
_, err = svc.PutObject(&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, "/"))
|
||||
|
@ -190,28 +141,3 @@ 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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user