-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dd8441
commit 94d0eef
Showing
41 changed files
with
2,035 additions
and
868 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ tmp | |
credentials | ||
main | ||
config.toml | ||
_ | ||
_ | ||
out | ||
bin |
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 |
---|---|---|
@@ -1,4 +1,36 @@ | ||
# Build all | ||
.PHONY: build | ||
build: | ||
./scripts/build.sh | ||
VERSION := $(shell git rev-parse --abbrev-ref HEAD) | ||
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ') | ||
COMMIT := $(shell git rev-parse --short HEAD) | ||
|
||
EXECUTABLE=komiser | ||
|
||
GO_LD_FLAGS += -X github.com/mlabouardy/komiser/internal.Version=$(VERSION) | ||
GO_LD_FLAGS += -X github.com/mlabouardy/komiser/internal.Buildtime=$(BUILDTIME) | ||
GO_LD_FLAGS += -X github.com/mlabouardy/komiser/internal.Commit=$(COMMIT) | ||
GO_FLAGS = -ldflags "$(GO_LD_FLAGS)" | ||
|
||
build: ## Build for the current platform | ||
go build -o bin/$(EXECUTABLE) $(GO_FLAGS) . | ||
@echo built: bin/$(EXECUTABLE) | ||
@echo version: $(VERSION) | ||
@echo commit: $(COMMIT) | ||
|
||
package: ## Build for all platforms | ||
env GOOS=windows GOARCH=amd64 go build -o bin/$(EXECUTABLE)_windows_amd64.exe $(GO_FLAGS) . | ||
env GOOS=linux GOARCH=amd64 go build -o bin/$(EXECUTABLE)_linux_amd64 $(GO_FLAGS) . | ||
env GOOS=darwin GOARCH=amd64 go build -o bin/$(EXECUTABLE)_darwin_amd64 $(GO_FLAGS) . | ||
env GOOS=darwin GOARCH=arm64 go build -o bin/$(EXECUTABLE)_darwin_arm64 $(GO_FLAGS) . | ||
@echo built: bin/$(EXECUTABLE)_windows_amd64.exe, bin/$(EXECUTABLE)_linux_amd64, bin/$(EXECUTABLE)_darwin_amd64, bin/$(EXECUTABLE)_darwin_arm64 | ||
@echo version: $(VERSION) | ||
@echo commit: $(COMMIT) | ||
|
||
test: ## Run tests | ||
go test -v ./... | ||
|
||
version: | ||
@echo version: $(VERSION) | ||
|
||
clean: ## Remove previous builds and clear test cache | ||
rm -f bin/$(EXECUTABLE)* | ||
go clean -testcache |
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,24 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "komiser", | ||
Short: "Cloud environment inspector", | ||
Long: `Komiser enables you to have a clear view into your cloud account, | ||
gives helpful advice to reduce the cost and secure your environment.`, | ||
} | ||
|
||
func Execute() { | ||
rootCmd.CompletionOptions.HiddenDefaultCmd = true | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() {} |
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,67 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/mlabouardy/komiser/internal" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var startCmd = &cobra.Command{ | ||
Use: "start", | ||
Short: "Run Komiser server", | ||
Long: ``, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
file, err := cmd.Flags().GetString("config") | ||
if err != nil { | ||
return err | ||
} | ||
if file == "" { | ||
return errors.New("you must specify a manifest with '--config path/url'") | ||
} | ||
|
||
regions, err := cmd.Flags().GetStringArray("regions") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
verbose, _ := cmd.Flags().GetBool("verbose") | ||
setupLogging(verbose) | ||
|
||
noTracking, _ := cmd.Flags().GetBool("no-tracking") | ||
if noTracking { | ||
log.Info("Tracking has been disabled") | ||
} | ||
|
||
port, err := cmd.Flags().GetInt("port") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = internal.Exec(port, file, noTracking, regions, cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(startCmd) | ||
startCmd.PersistentFlags().Int("port", 3000, `Port to start server on, default:"3000".`) | ||
startCmd.PersistentFlags().StringArray("regions", []string{}, "Restrict Komiser inspection to list of regions.") | ||
startCmd.PersistentFlags().String("config", "", "Path to configuration file.") | ||
startCmd.PersistentFlags().Bool("verbose", true, "Show verbose debug information.") | ||
startCmd.PersistentFlags().Bool("no-tracking", false, "Disable user analytics.") | ||
} | ||
|
||
func setupLogging(verbose bool) { | ||
if verbose { | ||
log.SetLevel(log.DebugLevel) | ||
log.Debugf("Debug logging is enabled") | ||
} else { | ||
log.SetLevel(log.InfoLevel) | ||
} | ||
} |
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,32 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mlabouardy/komiser/internal" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/text/cases" | ||
"golang.org/x/text/language" | ||
) | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Show tool version", | ||
Long: ``, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Komiser") | ||
showLine(cmd, "Version", internal.Version) | ||
showLine(cmd, "Go version", internal.GoVersion) | ||
showLine(cmd, "Commit", internal.Commit) | ||
showLine(cmd, "OS/Arch", fmt.Sprintf("%s/%s", internal.Os, internal.Arch)) | ||
showLine(cmd, "Built", internal.Buildtime) | ||
}, | ||
} | ||
|
||
func showLine(cmd *cobra.Command, title string, value string) { | ||
cmd.Printf(" %-16s %s\n", fmt.Sprintf("%s:", cases.Title(language.Und, cases.NoLower).String(title)), value) | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const environment = { | ||
production: true, | ||
API_URL: '' | ||
API_URL: '', | ||
GA_TRACKING_ID: 'G-9HF3HT6S6W' | ||
}; | ||
|
||
export default environment; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const environment = { | ||
production: false, | ||
API_URL: '' | ||
API_URL: '', | ||
GA_TRACKING_ID: 'G-9HF3HT6S6W' | ||
}; | ||
|
||
export default environment; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const environment = { | ||
production: false, | ||
API_URL: '' | ||
API_URL: '', | ||
GA_TRACKING_ID: 'G-9HF3HT6S6W' | ||
}; | ||
|
||
export default environment; |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const environment = { | ||
production: false, | ||
API_URL: 'http://localhost:3000' | ||
API_URL: 'http://localhost:3000', | ||
GA_TRACKING_ID: 'G-9HF3HT6S6W' | ||
}; | ||
|
||
export default environment; |
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
Oops, something went wrong.