Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
djelusic committed Sep 27, 2021
1 parent c6f3ffc commit e5ab1d5
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 107 deletions.
24 changes: 0 additions & 24 deletions aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
Expand Down Expand Up @@ -72,27 +69,6 @@ func NewFromProfile(profile string) (*AWS, error) {
return clientFromConfig(config), nil
}

func ListProfiles() ([]string, error) {
configFilePath := config.DefaultSharedConfigFilename()
buf, err := ioutil.ReadFile(configFilePath)
if err != nil {
return nil, fmt.Errorf("could not read AWS credentials file - %v", err)
}
profileRegex := regexp.MustCompile(`^\[profile (.*?)\]`)
var profiles []string
for _, line := range strings.Split(string(buf), "\n") {
if strings.HasPrefix(line, "[default]") {
profiles = append(profiles, "default")
continue
}
res := profileRegex.FindStringSubmatch(line)
if len(res) > 0 {
profiles = append(profiles, res[1])
}
}
return profiles, nil
}

func clientFromConfig(config aws.Config) *AWS {
return &AWS{
config: config,
Expand Down
16 changes: 10 additions & 6 deletions cli/mantil/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.
since, _ := cmd.Flags().GetDuration("since")
filter := cmd.Flag("filter-pattern").Value.String()
tail, _ := cmd.Flags().GetBool("follow")
stage, _ := cmd.Flags().GetString("stage")
stageName, _ := cmd.Flags().GetString("stage")
p, _ := getProject()
stage := p.Stage(stageName)
if stage == nil {
log.Fatalf("Stage %s not found", stageName)
}
var function string
if len(args) > 0 {
function = args[0]
} else {
function = selectFunction(p)
function = selectFunction(stage)
}
logGroup := config.ProjectResource(p.Name, stage, function)
aws := initialiseAWSSDK(p.Name, stage)
logGroup := config.ProjectResource(p.Name, stageName, function)
aws := initialiseAWSSDK(p.Name, stageName)
l := logs.New(aws)
if err := l.Fetch(logGroup, filter, since, tail); err != nil {
log.Fatal(err)
Expand All @@ -47,9 +51,9 @@ func init() {
rootCmd.AddCommand(logsCmd)
}

func selectFunction(p *config.Project) string {
func selectFunction(stage *config.Stage) string {
var funcNames []string
for _, f := range p.Functions {
for _, f := range stage.Functions {
funcNames = append(funcNames, f.Name)
}
prompt := promptui.Select{
Expand Down
42 changes: 0 additions & 42 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package config

import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
)

func Env(stageName string) (string, *Stage) {
Expand All @@ -29,42 +26,3 @@ export %s='%s'
EnvApiURL, url,
), stage
}

func SaveToken(projectName, token string) error {
home, err := os.UserHomeDir()
if err != nil {
return err
}
configDir := path.Join(home, ".mantil", projectName)

if err := os.MkdirAll(configDir, 0755); err != nil {
return err
}

config := path.Join(configDir, "config")
if err := ioutil.WriteFile(config, []byte(token), 0755); err != nil {
return err
}
return nil
}

func ReadToken(projectName string) (string, error) {
token := os.Getenv("MANTIL_TOKEN")
if token != "" {
return token, nil
}
home, err := os.UserHomeDir()
if err != nil {
return "", err
}
config := path.Join(home, ".mantil", projectName, "config")
data, err := ioutil.ReadFile(config)
if err != nil {
return "", err
}
token = string(data)
if token == "" {
return "", fmt.Errorf("token not found")
}
return token, nil
}
6 changes: 0 additions & 6 deletions config/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ type Function struct {
Env map[string]string `yaml:"env"`
}

type FunctionUpdate struct {
Name string
Hash string
S3Key string
}

type FunctionDefaults struct {
Prefix string `yaml:"prefix"`
MemorySize int `yaml:"memory_size"`
Expand Down
27 changes: 3 additions & 24 deletions config/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ const (
)

type Project struct {
Name string `yaml:"name"` // required
Bucket string `yaml:"bucket"`
Functions []*Function `yaml:"functions"`
PublicSites []*PublicSite `yaml:"public_sites"`
Stages []*Stage `yaml:"stages"`
}

type ProjectUpdate struct {
Function *FunctionUpdate
PublicSite *PublicSiteUpdate
Action UpdateAction
Name string `yaml:"name"` // required
Bucket string `yaml:"bucket"`
Stages []*Stage `yaml:"stages"`
}

type UpdateAction uint8
Expand Down Expand Up @@ -227,19 +219,6 @@ func FindProjectRoot(initialPath string) (string, error) {
}
}

func (p *Project) AddFunction(fun *Function) {
p.Functions = append(p.Functions, fun)
}

func (p *Project) RemoveFunction(fun string) {
for i, f := range p.Functions {
if fun == f.Name {
p.Functions = append(p.Functions[:i], p.Functions[i+1:]...)
break
}
}
}

func (s *Stage) AddFunctionDefaults() {
for _, f := range s.Functions {
if f.Path == "" {
Expand Down
5 changes: 0 additions & 5 deletions config/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ type PublicSite struct {
Bucket string `yaml:"bucket"`
Hash string `yaml:"hash"`
}

type PublicSiteUpdate struct {
Name string
Hash string
}

0 comments on commit e5ab1d5

Please sign in to comment.