Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
djelusic committed Jul 27, 2021
1 parent cf1b0a7 commit 321fbfd
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 404 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ mv funcs.zip $ASSETS_DIR/terraform/modules
zip -j dynamodb.zip $WORK_DIR/terraform-aws-modules/dynamodb/*.tf
mv dynamodb.zip $ASSETS_DIR/terraform/modules

(cd $ASSETS_DIR && go-bindata -pkg=assets -fs github/ terraform/modules/ terraform/templates/ aws/)
(cd $ASSETS_DIR && go-bindata -pkg=assets -fs terraform/modules/ terraform/templates/ aws/)
29 changes: 2 additions & 27 deletions internal/assets/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions internal/assets/github/mantil-workflow.yml

This file was deleted.

8 changes: 0 additions & 8 deletions internal/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ func New() (*AWS, error) {
}, nil
}

func (a *AWS) Credentials() (aws.Credentials, error) {
return a.config.Credentials.Retrieve(context.TODO())
}

func (a *AWS) DefaultRegion() string {
return a.config.Region
}

func (a *AWS) CreateS3Bucket(name, region string) error {
cbi := &s3.CreateBucketInput{
Bucket: aws.String(name),
Expand Down
105 changes: 0 additions & 105 deletions internal/mantil/organization.go
Original file line number Diff line number Diff line change
@@ -1,112 +1,7 @@
package mantil

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/atoz-technology/mantil-backend/internal/shell"
"github.com/atoz-technology/mantil-backend/internal/template"
)

var (
rootFolder = "/tmp"
templatesFolder = "/code/templates"
modulesFolder = "/code"
projectsBucket = "s3://atoz-technology-mantil-projects"
)

type Organization struct {
Name string
DNSZone string
CertArn string
}

func (o Organization) Folder() string {
return fmt.Sprintf("%s/%s", rootFolder, o.Name)
}

func (o Organization) S3Key() string {
return fmt.Sprintf("%s/%s", projectsBucket, o.Name)
}

func (o Organization) Pull() error {
return shell.AwsCli().SyncFrom(o.S3Key(), o.Folder())
}

func (o Organization) ProjectFolder(name string) string {
return fmt.Sprintf("%s/%s", o.Folder(), name)
}

func (o Organization) PushProject(name string, config interface{}) error {
buf, err := json.MarshalIndent(config, " ", " ")
if err != nil {
return err
}
if err := ioutil.WriteFile(o.ProjectFolder(name)+"/config.json", buf, 0644); err != nil {
return err
}
s3Key := fmt.Sprintf("%s/%s/%s", projectsBucket, o.Name, name)
return shell.AwsCli().SyncTo(s3Key, o.ProjectFolder(name))
}

func (o Organization) renderTemplate(templateName, project string, data interface{}) error {
return template.Exec(fmt.Sprintf("%s/%s/main.tf", templatesFolder, templateName),
data,
o.ProjectFolder(project)+"/main.tf",
)
}

func (o Organization) linkModulesSecrets(project string) error {
projectModulesFolder := o.ProjectFolder(project) + "/.modules"
if !shell.FolderExists(projectModulesFolder) {
if err := os.Symlink(modulesFolder, projectModulesFolder); err != nil {
return err
}
}
return nil
}

func (o Organization) PrepareProject(templateName, project string, data interface{}) error {
if err := os.MkdirAll(o.ProjectFolder(project), os.ModePerm); err != nil {
return err
}
if err := o.renderTemplate(templateName, project, data); err != nil {
return err
}
return o.linkModulesSecrets(project)
}

func (o *Organization) LoadProject(project string, data interface{}) error {
buf, err := ioutil.ReadFile(o.ProjectFolder(project) + "/config.json")
if err != nil {
return err
}
return json.Unmarshal(buf, data)
}

func (o *Organization) Load(name string) error {
org := Organization{
Name: name,
}
if err := org.Pull(); err != nil {
return err
}
buf, err := ioutil.ReadFile(org.Folder() + "/config.json")
if err != nil {
return err
}
return json.Unmarshal(buf, o)
}

func (o *Organization) load(name string) error {
org := Organization{
Name: name,
}
buf, err := ioutil.ReadFile(org.Folder() + "/config.json")
if err != nil {
return err
}
return json.Unmarshal(buf, o)
}
74 changes: 0 additions & 74 deletions internal/mantil/organization_test.go

This file was deleted.

64 changes: 0 additions & 64 deletions internal/mantil/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/atoz-technology/mantil-backend/internal/aws"
)
Expand Down Expand Up @@ -162,64 +159,3 @@ func (p *Project) AddFunctionDefaults() {
p.Functions[i] = f
}
}

type LocalProjectConfig struct {
Bucket string
GithubOrg string
}

func (p *Project) LocalConfig(githubOrg string) *LocalProjectConfig {
return &LocalProjectConfig{
Bucket: p.Bucket,
GithubOrg: githubOrg,
}
}

func (c *LocalProjectConfig) Save(path string) error {
buf, err := json.Marshal(c)
if err != nil {
return err
}
configDir := filepath.Join(path, "config")
if err := os.MkdirAll(configDir, os.ModePerm); err != nil {
return err
}
if err := ioutil.WriteFile(filepath.Join(path, localConfigPath), buf, 0644); err != nil {
return err
}
return nil
}

func LoadLocalConfig(projectRoot string) (*LocalProjectConfig, error) {
buf, err := ioutil.ReadFile(filepath.Join(projectRoot, localConfigPath))
if err != nil {
return nil, err
}
c := &LocalProjectConfig{}
if err := json.Unmarshal(buf, c); err != nil {
return nil, err
}
return c, nil
}

func FindProjectRoot(initialPath string) (string, error) {
currentPath := initialPath
for {
_, err := os.Stat(filepath.Join(currentPath, localConfigPath))
if err == nil {
abs, err := filepath.Abs(currentPath)
if err != nil {
return "", err
}
return abs, nil
}
currentPathAbs, err := filepath.Abs(currentPath)
if err != nil {
return "", err
}
if currentPathAbs == "/" {
return "", fmt.Errorf("no mantil project found")
}
currentPath += "/.."
}
}
Loading

0 comments on commit 321fbfd

Please sign in to comment.