Skip to content

Commit

Permalink
remove cli/commands package and reorganize code
Browse files Browse the repository at this point in the history
  • Loading branch information
djelusic committed Sep 30, 2021
1 parent 54a7f90 commit fa91314
Show file tree
Hide file tree
Showing 38 changed files with 195 additions and 195 deletions.
8 changes: 4 additions & 4 deletions api/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
)

type DataRequest struct {
Expand All @@ -13,11 +13,11 @@ type DataRequest struct {
}

type DataResponse struct {
Stage *config.Stage
Stage *workspace.Stage
}

type Data struct {
stage *config.Stage
stage *workspace.Stage
}

func New() *Data {
Expand All @@ -32,7 +32,7 @@ func (d *Data) Invoke(ctx context.Context, req *DataRequest) (*DataResponse, err
}

func (d *Data) init(req *DataRequest) error {
stage, err := config.LoadDeploymentState(req.ProjectName, req.StageName)
stage, err := workspace.LoadDeploymentState(req.ProjectName, req.StageName)
if err != nil {
return fmt.Errorf("error fetching stage %s for project %s - %w", req.StageName, req.ProjectName, err)
}
Expand Down
4 changes: 2 additions & 2 deletions api/data/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package data
import (
"testing"

"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestDataResponse(t *testing.T) {
d := &Data{
stage: &config.Stage{
stage: &workspace.Stage{
Name: "test-project",
},
}
Expand Down
34 changes: 17 additions & 17 deletions api/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import (

"github.com/mantil-io/mantil/api/log"
"github.com/mantil-io/mantil/aws"
"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
"github.com/mantil-io/mantil/terraform"
)

type Deploy struct {
projectName string
currentState *config.Stage
desiredState *config.Stage
rc *config.RuntimeConfig
currentState *workspace.Stage
desiredState *workspace.Stage
rc *workspace.RuntimeConfig
bucketName string
awsClient *aws.AWS
}

type DeployRequest struct {
ProjectName string
Stage *config.Stage
Stage *workspace.Stage
}

type DeployResponse struct{}
Expand All @@ -44,18 +44,18 @@ func (d *Deploy) init(req *DeployRequest) error {
if err != nil {
return fmt.Errorf("error initializing aws client - %w", err)
}
currentState, err := config.LoadDeploymentState(req.ProjectName, req.Stage.Name)
currentState, err := workspace.LoadDeploymentState(req.ProjectName, req.Stage.Name)
if errors.Is(err, aws.ErrNotFound) {
// new stage, deployment state doesn't exist yet
currentState = &config.Stage{}
currentState = &workspace.Stage{}
} else if err != nil {
return fmt.Errorf("error fetching deployment state - %w", err)
}
rc, err := config.LoadRuntimeConfig(awsClient)
rc, err := workspace.LoadRuntimeConfig(awsClient)
if err != nil {
return fmt.Errorf("error fetching runtime config - %w", err)
}
bucketName, err := config.Bucket(awsClient)
bucketName, err := workspace.Bucket(awsClient)
if err != nil {
return fmt.Errorf("error fetching bucket name - %w", err)
}
Expand All @@ -80,7 +80,7 @@ func (d *Deploy) deploy() (*DeployResponse, error) {
return nil, err
}
}
return nil, config.SaveDeploymentState(d.projectName, d.desiredState)
return nil, workspace.SaveDeploymentState(d.projectName, d.desiredState)
}

func (d *Deploy) processUpdates() (bool, error) {
Expand All @@ -96,7 +96,7 @@ func (d *Deploy) processUpdates() (bool, error) {
return false, nil
}

func funcsAddedOrRemoved(current, new *config.Stage) bool {
func funcsAddedOrRemoved(current, new *workspace.Stage) bool {
var oldFuncs, newFuncs []string
for _, f := range current.Functions {
oldFuncs = append(oldFuncs, f.Name)
Expand All @@ -107,7 +107,7 @@ func funcsAddedOrRemoved(current, new *config.Stage) bool {
return addedOrRemoved(oldFuncs, newFuncs)
}

func sitesAddedOrRemoved(current, new *config.Stage) bool {
func sitesAddedOrRemoved(current, new *workspace.Stage) bool {
var oldSites, newSites []string
for _, s := range current.PublicSites {
oldSites = append(oldSites, s.Name)
Expand All @@ -128,7 +128,7 @@ func addedOrRemoved(current, new []string) bool {
return false
}

func (d *Deploy) updateFunctions(oldStage, newStage *config.Stage) error {
func (d *Deploy) updateFunctions(oldStage, newStage *workspace.Stage) error {
for _, f := range newStage.Functions {
for _, of := range oldStage.Functions {
if f.Name != of.Name {
Expand Down Expand Up @@ -164,7 +164,7 @@ func (d *Deploy) applyInfrastructure() error {
if err := d.updateWebsitesConfig(sites); err != nil {
return err
}
d.desiredState.Endpoints = &config.StageEndpoints{
d.desiredState.Endpoints = &workspace.StageEndpoints{
Rest: url,
Ws: wsUrl,
}
Expand All @@ -176,7 +176,7 @@ func (d *Deploy) terraformCreate() (*terraform.Terraform, error) {
data := terraform.ProjectTemplateData{
Name: d.projectName,
Bucket: d.bucketName,
BucketPrefix: config.DeploymentBucketPrefix(d.projectName, stage.Name),
BucketPrefix: workspace.DeploymentBucketPrefix(d.projectName, stage.Name),
Functions: stage.Functions,
PublicSites: stage.PublicSites,
Region: d.awsClient.Region(),
Expand All @@ -191,9 +191,9 @@ func (d *Deploy) terraformCreate() (*terraform.Terraform, error) {
return tf, tf.Create()
}

func (d *Deploy) updateLambdaFunction(f *config.Function) error {
func (d *Deploy) updateLambdaFunction(f *workspace.Function) error {
log.Info("updating function %s...", f.Name)
lambdaName := config.ProjectResource(d.projectName, d.desiredState.Name, f.Name)
lambdaName := workspace.ProjectResource(d.projectName, d.desiredState.Name, f.Name)
var err error
if f.S3Key != "" {
err = d.awsClient.UpdateLambdaFunctionCodeFromS3(lambdaName, d.bucketName, f.S3Key)
Expand Down
12 changes: 6 additions & 6 deletions api/destroy/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/mantil-io/mantil/aws"
"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
"github.com/mantil-io/mantil/terraform"
)

Expand All @@ -18,7 +18,7 @@ type DestroyResponse struct{}

type Destroy struct {
req *DestroyRequest
stage *config.Stage
stage *workspace.Stage
bucketName string
region string
}
Expand All @@ -35,15 +35,15 @@ func (d *Destroy) Invoke(ctx context.Context, req *DestroyRequest) (*DestroyResp
}

func (d *Destroy) init(req *DestroyRequest) error {
stage, err := config.LoadDeploymentState(req.ProjectName, req.StageName)
stage, err := workspace.LoadDeploymentState(req.ProjectName, req.StageName)
if err != nil {
return err
}
awsClient, err := aws.New()
if err != nil {
return err
}
bucketName, err := config.Bucket(awsClient)
bucketName, err := workspace.Bucket(awsClient)
if err != nil {
return err
}
Expand All @@ -58,7 +58,7 @@ func (d *Destroy) destroy() (*DestroyResponse, error) {
if err := d.terraformDestroy(); err != nil {
return nil, fmt.Errorf("could not terraform destroy - %w", err)
}
if err := config.DeleteDeploymentState(d.req.ProjectName, d.req.StageName); err != nil {
if err := workspace.DeleteDeploymentState(d.req.ProjectName, d.req.StageName); err != nil {
return nil, fmt.Errorf("could not delete stage %s - %w", d.req.StageName, err)
}
return &DestroyResponse{}, nil
Expand All @@ -77,7 +77,7 @@ func (d *Destroy) terraformProjectTemplateData() terraform.ProjectTemplateData {
Name: d.req.ProjectName,
Stage: d.req.StageName,
Bucket: d.bucketName,
BucketPrefix: config.DeploymentBucketPrefix(d.req.ProjectName, d.req.StageName),
BucketPrefix: workspace.DeploymentBucketPrefix(d.req.ProjectName, d.req.StageName),
Region: d.region,
}
}
4 changes: 2 additions & 2 deletions api/destroy/destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package destroy
import (
"testing"

"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
"github.com/stretchr/testify/assert"
)

Expand All @@ -13,7 +13,7 @@ func TestTerraformProjectTemplateData(t *testing.T) {
ProjectName: "test-project",
StageName: "test-stage",
},
stage: &config.Stage{
stage: &workspace.Stage{
Name: "test-stage",
},
bucketName: "bucket",
Expand Down
14 changes: 7 additions & 7 deletions api/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/mantil-io/mantil/aws"

"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
)

type AWS interface {
Expand All @@ -31,7 +31,7 @@ type SecurityResponse struct {

type Security struct {
req *SecurityRequest
stage *config.Stage
stage *workspace.Stage
bucketName string
awsClient AWS
}
Expand All @@ -52,12 +52,12 @@ func (s *Security) init(req *SecurityRequest) error {
if err != nil {
return fmt.Errorf("error initializing aws client - %w", err)
}
var stage *config.Stage
var stage *workspace.Stage
if req.StageName != "" {
// ignore this error as deployment state won't exist for newly created stages
stage, _ = config.LoadDeploymentState(req.ProjectName, req.StageName)
stage, _ = workspace.LoadDeploymentState(req.ProjectName, req.StageName)
}
bucketName, err := config.Bucket(awsClient)
bucketName, err := workspace.Bucket(awsClient)
if err != nil {
return err
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func (s *Security) projectPolicyTemplateData() (*projectPolicyTemplateData, erro
}
if s.stage != nil {
ppt.PublicSites = s.stage.PublicSites
ppt.LogGroup = config.ProjectResource(s.req.ProjectName, s.stage.Name)
ppt.LogGroup = workspace.ProjectResource(s.req.ProjectName, s.stage.Name)
}
return ppt, nil
}
Expand Down Expand Up @@ -146,7 +146,7 @@ type projectPolicyTemplateData struct {
Bucket string
Region string
AccountID string
PublicSites []*config.PublicSite
PublicSites []*workspace.PublicSite
LogGroup string
}

Expand Down
6 changes: 3 additions & 3 deletions api/security/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/mantil-io/mantil/aws"
"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
"github.com/sergi/go-diff/diffmatchpatch"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -78,9 +78,9 @@ func TestProjectCredentialsWithStage(t *testing.T) {
ProjectName: "test-project",
StageName: "test-stage",
},
stage: &config.Stage{
stage: &workspace.Stage{
Name: "test-stage",
PublicSites: []*config.PublicSite{
PublicSites: []*workspace.PublicSite{
{Bucket: "publicSite1"},
{Bucket: "publicSite2"},
},
Expand Down
6 changes: 3 additions & 3 deletions api/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/mantil-io/mantil/api/dto"
"github.com/mantil-io/mantil/aws"
"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
"github.com/mantil-io/mantil/terraform"
)

Expand Down Expand Up @@ -62,7 +62,7 @@ func (s *Setup) init(req *dto.SetupRequest, awsClient *aws.AWS) error {
return fmt.Errorf("error initializing AWS client - %w", err)
}
}
bucketName, err := config.Bucket(awsClient)
bucketName, err := workspace.Bucket(awsClient)
if err != nil {
return err
}
Expand All @@ -73,7 +73,7 @@ func (s *Setup) init(req *dto.SetupRequest, awsClient *aws.AWS) error {
}

func (s *Setup) saveConfig() error {
return config.SaveRuntimeConfig(s.awsClient, &config.RuntimeConfig{
return workspace.SaveRuntimeConfig(s.awsClient, &workspace.RuntimeConfig{
// TODO: sto ce mi ovaj version kada se nigdje ne koristi
Version: s.req.Version,
FunctionsBucket: s.req.FunctionsBucket,
Expand Down
10 changes: 5 additions & 5 deletions api/ws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/mantil-io/mantil.go"
"github.com/mantil-io/mantil.go/pkg/proto"
"github.com/mantil-io/mantil/aws"
"github.com/mantil-io/mantil/config"
"github.com/mantil-io/mantil/workspace"
)

type Handler struct {
Expand All @@ -34,8 +34,8 @@ func NewHandler() (*Handler, error) {
return &Handler{
store: store,
aws: aws,
projectName: os.Getenv(config.EnvProjectName),
stageName: os.Getenv(config.EnvStageName),
projectName: os.Getenv(workspace.EnvProjectName),
stageName: os.Getenv(workspace.EnvStageName),
}, nil
}

Expand Down Expand Up @@ -127,9 +127,9 @@ func (h *Handler) clientRequest(client *client, m *proto.Message) error {
function := uriParts[0]
var functionName string
if h.projectName != "" {
functionName = config.ProjectResource(h.projectName, h.stageName, function)
functionName = workspace.ProjectResource(h.projectName, h.stageName, function)
} else {
functionName = config.RuntimeResource(function)
functionName = workspace.RuntimeResource(function)
}
invoker, err := mantil.NewLambdaInvoker(functionName, "")
if err != nil {
Expand Down
Loading

0 comments on commit fa91314

Please sign in to comment.