Skip to content

Commit

Permalink
Merge pull request #11 from gruz0/refactor/combine-all-apps-into-one-…
Browse files Browse the repository at this point in the history
…single-app

Combine all apps into one single app
  • Loading branch information
gruz0 authored May 18, 2024
2 parents e013aab + 5ee26b9 commit 1be6f57
Show file tree
Hide file tree
Showing 21 changed files with 964 additions and 408 deletions.
15 changes: 0 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,12 @@ BIN_DIR=./bin
WEB3SAFE_BINARY_NAME=web3safe
WEB3SAFE_CMD_DIR=$(CMD_DIR)/$(WEB3SAFE_BINARY_NAME)

DOTENVANALYZER_BINARY_NAME=dotenvanalyzer
DOTENVANALYZER_CMD_DIR=$(CMD_DIR)/$(DOTENVANALYZER_BINARY_NAME)

ENVANALYZER_BINARY_NAME=envanalyzer
ENVANALYZER_CMD_DIR=$(CMD_DIR)/$(ENVANALYZER_BINARY_NAME)

YAMLANALYZER_BINARY_NAME=yamlanalyzer
YAMLANALYZER_CMD_DIR=$(CMD_DIR)/$(YAMLANALYZER_BINARY_NAME)

build: clean
$(GOBUILD) -o $(BIN_DIR)/$(WEB3SAFE_BINARY_NAME) $(WEB3SAFE_CMD_DIR)/...
$(GOBUILD) -o $(BIN_DIR)/$(DOTENVANALYZER_BINARY_NAME) $(DOTENVANALYZER_CMD_DIR)/...
$(GOBUILD) -o $(BIN_DIR)/$(ENVANALYZER_BINARY_NAME) $(ENVANALYZER_CMD_DIR)/...
$(GOBUILD) -o $(BIN_DIR)/$(YAMLANALYZER_BINARY_NAME) $(YAMLANALYZER_CMD_DIR)/...

clean:
$(GOCLEAN)
rm -f $(WEB3SAFE_BINARY_NAME)
rm -f $(DOTENVANALYZER_BINARY_NAME)
rm -f $(ENVANALYZER_BINARY_NAME)
rm -f $(YAMLANALYZER_BINARY_NAME)

deps:
$(GOCMD) mod tidy
Expand Down
90 changes: 63 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,55 +45,91 @@ Web3Safe is a command-line tool written in Go. To install it, follow these steps
make build
```

3. All apps will be placed inside `bin` directory:
3. App will be placed inside `bin` directory:
```
dotenvanalyzer
envanalyzer
yamlanalyzer
web3safe
```

Web3Safe includes three tools: Web3Safe itself, Shell ENV Analyzer and Dotenv
Analyzer.
### Docker

### Web3Safe
TBD

This tool is designed for creating a configuration file for the other apps.
## Usage

- `-help`: Show all the available commands.
- `-generateConfig`: Generate a new configuration file.
### Create a new configuration file

### EnvAnalyzer
```sh
web3safe config -create [-config "/path/to/config.yml"] [-force]
```

This tool scans the current user's environment variables and display any
### Print the default config (or a given config) to your terminal

```sh
web3safe config -print [-config "/path/to/config.yml"]
```

### Analyze shell ENV variables

This tool scans the current user's shell environment variables and display any
sensitive information found.

You can also customize the analysis by providing additional flags:
```sh
web3safe shellenv [-config "/path/to/config.yml"]
```

Example:

```sh
$ MNEMONIC=test web3safe shellenv

- `-help`: Show all the available commands.
- `-config`: Specify a custom configuration file for rule customization.
Shell ENV has a sensitive variable: MNEMONIC
```

### DotEnvAnalyzer
### Analyze dotenv (.env) files

By default, this tool scans .env files starting from a given directory
recursively and display any sensitive information found inside `.env` files.
```sh
web3safe dotenv [-config "/path/to/config.yml"]
```

You can also customize the analysis by providing additional flags:

- `-help`: Show all the available commands.
- `-config`: Specify a custom configuration file for rule customization.
- `-path`: Path to start scan from (default: current dir).
- `-dir`: Path to the directory to scan
- `-recursive`: If set, the directory will be scanned recursively
- `-file`: Path to the file to scan

### YamlAnalyzer
Example:

By default, this tool scans YAML files (`yml` and `yaml`) starting from a given
directory recursively and display any sensitive information found inside files.
```sh
$ web3safe dotenv -dir . -recursive

samples/.env:5: found sensitive variable MNEMONIC_WORDS
samples/.env:7: found sensitive variable private_key
samples/.env.export:1: found sensitive variable PRIVATE_KEY
samples/.env.export:2: found sensitive variable BINANCE_ACCOUNT_PRIVATE_KEY
```

### Analyze YAML files

```sh
web3safe yaml [-config "/path/to/config.yml"]
```

You can also customize the analysis by providing additional flags:

- `-help`: Show all the available commands.
- `-config`: Specify a custom configuration file for rule customization.
- `-path`: Path to start scan from (default: current dir).
- `-dir`: Path to the directory to scan
- `-recursive`: If set, the directory will be scanned recursively
- `-file`: Path to the file to scan

Example:

```sh
$ web3safe yaml -dir . -recursive

samples/config.yml: found sensitive key "PASSWORD" in .nested.inside.PASSWORD
samples/config.yml: found sensitive key "MNEMONIC" in .nested.inside.MNEMONIC
samples/playbook.yml: found sensitive key "password" in [0].password
samples/playbook.yml: found sensitive key "mnemonic" in [0].env.mnemonic
```

## Contributing

Expand Down
55 changes: 0 additions & 55 deletions cmd/dotenvanalyzer/main.go

This file was deleted.

55 changes: 0 additions & 55 deletions cmd/envanalyzer/main.go

This file was deleted.

30 changes: 16 additions & 14 deletions cmd/web3safe/main.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
package main

import (
"errors"
"fmt"
"os"

"github.com/gruz0/web3safe/internal/config"
"github.com/gruz0/web3safe/internal/flags"
"github.com/gruz0/web3safe/internal/app"
"github.com/gruz0/web3safe/internal/utils"
)

func main() {
flags := flags.ParseFlags()
success, err := app.Run(os.Args)
if err != nil {
var appError *app.Error

if flags.GenerateConfig {
generateConfig()
}
}
if errors.As(err, &appError) {
fmt.Fprintln(os.Stderr, appError.Error())
os.Exit(appError.ExitCode())
}

func generateConfig() {
newConfigFilePath := config.GetDefaultConfigFilePath()
fmt.Fprintf(os.Stderr, "Unhandled error: %v", err)
os.Exit(utils.ExitError)
}

if err := config.GenerateConfig(newConfigFilePath); err != nil {
fmt.Fprintf(os.Stderr, "Error generating config: %v\n", err)
os.Exit(1)
if success {
os.Exit(utils.ExitSuccess)
}

fmt.Fprintf(os.Stdout, "New configuration file generated at %s\n", newConfigFilePath)
os.Exit(0)
os.Exit(utils.ExitError)
}
55 changes: 0 additions & 55 deletions cmd/yamlanalyzer/main.go

This file was deleted.

Loading

0 comments on commit 1be6f57

Please sign in to comment.