This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from ZupIT/ritchie-2.0.0
Ritchie 2.0.0
- Loading branch information
Showing
225 changed files
with
6,950 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM alpine:3.12 | ||
USER root | ||
|
||
RUN mkdir /rit | ||
COPY . /rit | ||
RUN sed -i 's/\r//g' /rit/set_umask.sh | ||
RUN sed -i 's/\r//g' /rit/run.sh | ||
RUN chmod +x /rit/set_umask.sh | ||
|
||
WORKDIR /app | ||
ENTRYPOINT ["/rit/set_umask.sh"] | ||
CMD ["/rit/run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Go parameters | ||
BIN_FOLDER=bin | ||
SH=$(BIN_FOLDER)/run.sh | ||
BAT=$(BIN_FOLDER)/run.bat | ||
BIN_NAME=main | ||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOTEST=$(GOCMD) test | ||
CMD_PATH=main.go | ||
BIN_FOLDER_DARWIN=../$(BIN_FOLDER)/darwin | ||
BIN_DARWIN=$(BIN_FOLDER_DARWIN)/$(BIN_NAME) | ||
BIN_FOLDER_LINUX=../$(BIN_FOLDER)/linux | ||
BIN_LINUX=$(BIN_FOLDER_LINUX)/$(BIN_NAME) | ||
BIN_FOLDER_WINDOWS=../$(BIN_FOLDER)/windows | ||
BIN_WINDOWS=$(BIN_FOLDER_WINDOWS)/$(BIN_NAME).exe | ||
|
||
|
||
build: go-build sh-unix bat-windows docker | ||
|
||
go-build: | ||
cd src; mkdir -p $(BIN_FOLDER_DARWIN) $(BIN_FOLDER_LINUX) $(BIN_FOLDER_WINDOWS) | ||
#LINUX | ||
cd src; CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o '$(BIN_LINUX)' $(CMD_PATH) | ||
#MAC | ||
cd src; GOOS=darwin GOARCH=amd64 $(GOBUILD) -o '$(BIN_DARWIN)' $(CMD_PATH) | ||
#WINDOWS 64 | ||
cd src; GOOS=windows GOARCH=amd64 $(GOBUILD) -o '$(BIN_WINDOWS)' $(CMD_PATH) | ||
|
||
sh-unix: | ||
echo '#!/bin/sh' > $(SH) | ||
echo 'if [ $$(uname) = "Darwin" ]; then' >> $(SH) | ||
echo ' "$$(dirname "$$0")"/darwin/$(BIN_NAME)' >> $(SH) | ||
echo 'else' >> $(SH) | ||
echo ' "$$(dirname "$$0")"/linux/$(BIN_NAME)' >> $(SH) | ||
echo 'fi' >> $(SH) | ||
chmod +x $(SH) | ||
|
||
bat-windows: | ||
echo '@ECHO OFF' > $(BAT) | ||
echo 'SET mypath=%~dp0' >> $(BAT) | ||
echo 'start /B /WAIT %mypath:~0,-1%/windows/main.exe' >> $(BAT) | ||
|
||
docker: | ||
cp Dockerfile set_umask.sh $(BIN_FOLDER) | ||
|
||
test: | ||
$(GOTEST) -short `go list ./... | grep -v vendor/` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Ritchie Formula | ||
|
||
## command | ||
|
||
```bash | ||
rit aws clean bucket | ||
``` | ||
|
||
## description | ||
|
||
For use this formula run before: | ||
|
||
```bash | ||
rit set credential | ||
``` | ||
|
||
for add AWS credential. | ||
|
||
Formula receive field in env REGION and has received | ||
(CREDENTIAL_AWS_ACCESSKEYID, CREDENTIAL_AWS_SECRETACCESSKEY) in envs | ||
(ACCESS_KEY, SECRET_ACCESS_KEY). | ||
|
||
Formula receive bucket field in env BUCKET. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
:: Go parameters | ||
echo off | ||
SETLOCAL | ||
SET BINARY_NAME=main | ||
SET GOCMD=go | ||
SET GOBUILD=%GOCMD% build | ||
SET CMD_PATH=main.go | ||
SET BIN_FOLDER=..\bin | ||
SET DIST_WIN_DIR=%BIN_FOLDER%\windows | ||
SET DIST_LINUX_DIR=%BIN_FOLDER%\linux | ||
SET BIN_WIN=%BINARY_NAME%.exe | ||
SET BAT_FILE=%BIN_FOLDER%\run.bat | ||
SET SH_FILE=%BIN_FOLDER%\run.sh | ||
|
||
:build | ||
cd src | ||
mkdir %DIST_WIN_DIR% | ||
SET GO111MODULE=on | ||
for /f %%i in ('go list -m') do set MODULE=%%i | ||
CALL :windows | ||
CALL :linux | ||
if %errorlevel% neq 0 exit /b %errorlevel% | ||
GOTO CP_DOCKER | ||
GOTO DONE | ||
cd .. | ||
|
||
:windows | ||
SET CGO_ENABLED= | ||
SET GOOS=windows | ||
SET GOARCH=amd64 | ||
%GOBUILD% -tags release -o %DIST_WIN_DIR%\%BIN_WIN% %CMD_PATH% | ||
echo @ECHO OFF > %BAT_FILE% | ||
echo SET mypath=%%~dp0 >> %BAT_FILE% | ||
echo start /B /WAIT %%mypath:~0,-1%%/windows/main.exe >> %BAT_FILE% | ||
GOTO DONE | ||
|
||
:linux | ||
SET CGO_ENABLED=0 | ||
SET GOOS=linux | ||
SET GOARCH=amd64 | ||
%GOBUILD% -tags release -o %DIST_LINUX_DIR%\%BINARY_NAME% %CMD_PATH% | ||
echo "$(dirname "$0")"/linux/%BINARY_NAME% > %SH_FILE% | ||
GOTO DONE | ||
|
||
:CP_DOCKER | ||
copy ..\Dockerfile %BIN_FOLDER% | ||
copy ..\set_umask.sh %BIN_FOLDER% | ||
GOTO DONE | ||
:DONE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"dockerImageBuilder": "cimg/go:1.14", | ||
"inputs": [ | ||
{ | ||
"name": "access_key", | ||
"type": "CREDENTIAL_AWS_ACCESSKEYID" | ||
}, | ||
{ | ||
"name": "secret_access_key", | ||
"type": "CREDENTIAL_AWS_SECRETACCESSKEY" | ||
}, | ||
{ | ||
"cache": { | ||
"active": true, | ||
"newLabel": "Type new value. ", | ||
"qty": 6 | ||
}, | ||
"label": "Type your region [ e.g us-east-1 ]: ", | ||
"name": "region", | ||
"type": "text" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"long": "Clean bucket AWS", | ||
"short": "Clean bucket AWS" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Clean bucket AWS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"execution": [ | ||
"local", | ||
"docker" | ||
], | ||
"os": { | ||
"deps": [], | ||
"support": [ | ||
"windows", | ||
"mac", | ||
"linux" | ||
] | ||
}, | ||
"tags": [ | ||
"aws", | ||
"clean", | ||
"bucket" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
umask 0011 | ||
$1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module aws/bucket | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/aws/aws-sdk-go v1.32.2 | ||
github.com/fatih/color v1.9.0 | ||
github.com/go-openapi/strfmt v0.19.5 // indirect | ||
github.com/gosuri/uitable v0.0.4 | ||
github.com/jedib0t/go-pretty v4.3.0+incompatible | ||
github.com/manifoldco/promptui v0.7.0 | ||
github.com/mattn/go-runewidth v0.0.9 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"aws/bucket/pkg/bucket" | ||
"os" | ||
) | ||
|
||
func main() { | ||
loadInputs().Run() | ||
} | ||
|
||
func loadInputs() bucket.Inputs { | ||
return bucket.Inputs{ | ||
Key: os.Getenv("ACCESS_KEY"), | ||
Secret: os.Getenv("SECRET_ACCESS_KEY"), | ||
Region: os.Getenv("REGION"), | ||
BucketName: os.Getenv("BUCKET"), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package bucket | ||
|
||
import ( | ||
"aws/bucket/pkg/prompt" | ||
"fmt" | ||
|
||
"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" | ||
) | ||
|
||
type Inputs struct { | ||
Key string | ||
Secret string | ||
Region string | ||
BucketName string | ||
Command string | ||
} | ||
|
||
func (in Inputs) Run() { | ||
if in.Key == "" || in.Secret == "" { | ||
fmt.Println("Verify your credentials saved! Not received.") | ||
return | ||
} | ||
sess, err := session.NewSession(&aws.Config{ | ||
Region: aws.String(in.Region), | ||
Credentials: credentials.NewStaticCredentials(in.Key, in.Secret, ""), | ||
}) | ||
if err != nil { | ||
fmt.Println("Failed to create session, verify credentials") | ||
return | ||
} | ||
svc := s3.New(sess) | ||
in.runClean(svc) | ||
} | ||
|
||
func (in Inputs) runClean(svc *s3.S3) { | ||
res, err := in.list(svc) | ||
if err != nil { | ||
fmt.Printf("Error list bucket to clean, error: %v", err) | ||
} | ||
var bItems []string | ||
for _, b := range res.Buckets { | ||
bItems = append(bItems, aws.StringValue(b.Name)) | ||
} | ||
if len(bItems) == 0 { | ||
fmt.Printf("Not found bucket to clean") | ||
return | ||
} | ||
bSelect, _ := prompt.List("Select bucket to clean: ", bItems) | ||
confirm, _ := prompt.List(fmt.Sprintf("Confirm clean bucket name: %s", bSelect), []string{"NO", "YES"}) | ||
switch confirm { | ||
case "NO": | ||
fmt.Printf("Bucket %s not cleaned\n", bSelect) | ||
case "YES": | ||
fmt.Printf("Cleaning...") | ||
listObjectsInput := &s3.ListObjectsInput{ | ||
Bucket: aws.String(bSelect), | ||
MaxKeys: aws.Int64(20), | ||
} | ||
|
||
svc.ListObjectsPages(listObjectsInput, func(page *s3.ListObjectsOutput, lastPage bool) bool { | ||
for _, value := range page.Contents { | ||
deleteObjectInput := &s3.DeleteObjectInput{ | ||
Bucket: aws.String(bSelect), | ||
Key: value.Key, | ||
} | ||
|
||
_, err := svc.DeleteObject(deleteObjectInput) | ||
if err != nil { | ||
fmt.Printf("Error on delete object %s, error: %v\n", err) | ||
return false | ||
} | ||
|
||
fmt.Println("Deleted object: ", *value.Key) | ||
} | ||
return true | ||
}) | ||
|
||
fmt.Printf("Bucket %s cleaned.\n", bSelect) | ||
} | ||
} | ||
|
||
func (in Inputs) list(svc *s3.S3) (*s3.ListBucketsOutput, error) { | ||
result, err := svc.ListBuckets(nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed list bucket, error: %s\n", err.Error()) | ||
} | ||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package prompt | ||
|
||
import ( | ||
"github.com/manifoldco/promptui" | ||
) | ||
|
||
// list show a prompt with options and parse to string. | ||
func List(name string, items []string) (string, error) { | ||
prompt := promptui.Select{ | ||
Items: items, | ||
Templates: defaultSelectTemplate(name), | ||
} | ||
_, result, err := prompt.Run() | ||
return result, err | ||
} | ||
|
||
func defaultSelectTemplate(label string) *promptui.SelectTemplates { | ||
return &promptui.SelectTemplates{ | ||
Label: label, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"long": "Clean AWS objects", | ||
"short": "Clean AWS objects" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Clean AWS objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"long": "Generate beagle objects", | ||
"short": "Generate beagle objects" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Generate beagle objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM cimg/base:stable-20.04 | ||
|
||
USER root | ||
|
||
COPY . / | ||
|
||
RUN sed -i 's/\r//g' /set_umask.sh | ||
RUN sed -i 's/\r//g' /run.sh | ||
RUN chmod +x /set_umask.sh | ||
RUN mkdir /app | ||
|
||
ENV DOCKER_EXECUTION=true | ||
ENV CURRENT_PWD=/app | ||
|
||
WORKDIR / | ||
|
||
ENTRYPOINT ["/set_umask.sh"] | ||
CMD ["/run.sh"] |
Oops, something went wrong.