Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #130 from ZupIT/ritchie-2.0.0
Browse files Browse the repository at this point in the history
Ritchie 2.0.0
  • Loading branch information
GuillaumeFalourd authored Aug 12, 2020
2 parents a8522fa + bc5159b commit 4c03810
Show file tree
Hide file tree
Showing 225 changed files with 6,950 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .circleci/validation/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func getFullContentFromFormula(root string) map[string]string {
panic(err)
}
for _, file := range files {
if strings.Contains(file, "src/main.") && !strings.HasPrefix(file, "../../templates") {
if strings.Contains(file, "src/main.") && !strings.HasPrefix(file, "../../templates") && !strings.Contains(file, "_vendor/") {
fileX := strings.Split(file, "/src/main.")
required[fileX[0]] = fileX[1]
}
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#https://pre-commit.com/hooks.html
exclude: '_vendor/.*$'
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
Expand Down
12 changes: 12 additions & 0 deletions aws/clean/bucket/Dockerfile
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"]
47 changes: 47 additions & 0 deletions aws/clean/bucket/Makefile
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/`
23 changes: 23 additions & 0 deletions aws/clean/bucket/README.md
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.
49 changes: 49 additions & 0 deletions aws/clean/bucket/build.bat
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
23 changes: 23 additions & 0 deletions aws/clean/bucket/config.json
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"
}
]
}
4 changes: 4 additions & 0 deletions aws/clean/bucket/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "Clean bucket AWS",
"short": "Clean bucket AWS"
}
1 change: 1 addition & 0 deletions aws/clean/bucket/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean bucket AWS
19 changes: 19 additions & 0 deletions aws/clean/bucket/metadata.json
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"
]
}
3 changes: 3 additions & 0 deletions aws/clean/bucket/set_umask.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
umask 0011
$1
13 changes: 13 additions & 0 deletions aws/clean/bucket/src/go.mod
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
)
19 changes: 19 additions & 0 deletions aws/clean/bucket/src/main.go
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"),
}
}
91 changes: 91 additions & 0 deletions aws/clean/bucket/src/pkg/bucket/bucket.go
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
}
21 changes: 21 additions & 0 deletions aws/clean/bucket/src/pkg/prompt/prompt.go
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,
}
}
4 changes: 4 additions & 0 deletions aws/clean/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "Clean AWS objects",
"short": "Clean AWS objects"
}
1 change: 1 addition & 0 deletions aws/clean/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean AWS objects
4 changes: 4 additions & 0 deletions beagle/generate/help.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"long": "Generate beagle objects",
"short": "Generate beagle objects"
}
1 change: 1 addition & 0 deletions beagle/generate/help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Generate beagle objects
18 changes: 18 additions & 0 deletions beagle/generate/scaffold/Dockerfile
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"]
Loading

0 comments on commit 4c03810

Please sign in to comment.