Skip to content

Commit

Permalink
Merge pull request #135 from dream11/development
Browse files Browse the repository at this point in the history
Release odin version 1.2.0-beta.2
  • Loading branch information
sarveshdream11 authored Aug 11, 2022
2 parents 67f7a04 + 2fd9389 commit 053e744
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Type struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
Version string `yaml:"version,omitempty" json:"version,omitempty"`
TotalVersions int `yaml:"totalVersions,omitempty" json:"totalVersions,omitempty"`
DeploymentTypes []string `yaml:"deployment_types,omitempty" json:"deployment_types,omitempty"`
CreatedBy string `yaml:"createdBy,omitempty" json:"createdBy,omitempty"`
UpdatedBy string `yaml:"updatedBy,omitempty" json:"updatedBy,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty" json:"createdAt,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions api/envtype/envtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package envtype

// ListResponse interface
type ListTypeResponse struct {
Response []string `yaml:"resp,omitempty" json:"resp,omitempty"`
}
2 changes: 1 addition & 1 deletion api/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type DetailResponse struct {
// Status interface
type Status struct {
Name string `yaml:"name,omitempty" json:"name,omitempty"`
VM string `yaml:"vm,omitempty" json:"vm,omitempty"`
AWS_EC2 string `yaml:"aws_ec2,omitempty" json:"aws_ec2,omitempty"`
Container string `yaml:"container,omitempty" json:"container,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type application struct {
// App (Application) interface
var App application = application{
Name: "odin",
Version: "1.2.0-beta",
Version: "1.2.0-beta.2",
}
25 changes: 25 additions & 0 deletions internal/backend/envtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package backend

import (
"encoding/json"

"github.com/dream11/odin/api/envtype"
)

// Env entity
type EnvType struct{}

// root entity
var envEntityType = "envtypes"

// ListEnv : list all environment(s) with filters
func (e *EnvType) ListEnvType() ([]string, error) {
client := newApiClient()
response := client.actionWithRetry(envEntityType+"/", "GET", nil)
response.Process(true) // process response and exit if error

var envTypeResponse envtype.ListTypeResponse
err := json.Unmarshal(response.Body, &envTypeResponse)

return envTypeResponse.Response, err
}
3 changes: 3 additions & 0 deletions internal/command/command_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func CommandsCatalog() map[string]cli.CommandFactory {
"set env": func() (cli.Command, error) {
return &commands.Env{Set: true}, nil
},
"list env-type": func() (cli.Command, error) {
return &commands.EnvType{List: true}, nil
},

// Verbs for `component-type` resource
"list component-type": func() (cli.Command, error) {
Expand Down
7 changes: 5 additions & 2 deletions internal/command/commands/componentType.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"flag"
"fmt"
"strings"

"github.com/dream11/odin/internal/backend"
"github.com/dream11/odin/pkg/table"
Expand Down Expand Up @@ -37,20 +38,22 @@ func (c *ComponentType) Run(args []string) int {
var tableHeaders []string
var tableData [][]interface{}
if len(*componentTypeName) == 0 {
tableHeaders = []string{"Component Name", "Latest Version", "Total Versions Available"}
tableHeaders = []string{"Component Name", "Latest Version", "Deployemnt Types", "Total Versions Available"}
for _, componentType := range componentTypeList {
tableData = append(tableData, []interface{}{
componentType.Name,
componentType.Version,
strings.Join(componentType.DeploymentTypes, ", "),
componentType.TotalVersions,
})
}
} else {
tableHeaders = []string{"Component Name", "Version"}
tableHeaders = []string{"Component Name", "Version", "Deployemnt Types"}
for _, componentType := range componentTypeList {
tableData = append(tableData, []interface{}{
componentType.Name,
componentType.Version,
strings.Join(componentType.DeploymentTypes, ", "),
})
}
}
Expand Down
17 changes: 15 additions & 2 deletions internal/command/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ func (e *Env) Run(args []string) int {
}

if e.Create {
emptyParameters := emptyParameters(map[string]string{"--env-type": *env})
emptyParameters := emptyParameters(map[string]string{"--env-type": *env, "--name": *name})
if len(emptyParameters) == 0 {

if len(*name) > 9 {
e.Logger.Error("Env Name should not be of length more than 9")
return 1
}
envConfig := environment.Env{
EnvType: *env,
Account: *providerAccount,
Name: *name,
}

envClient.CreateEnvStream(envConfig)
Expand Down Expand Up @@ -187,6 +191,15 @@ func (e *Env) Run(args []string) int {
}
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
val, err := e.Input.Ask("Please re enter the Env Name:")
if err != nil {
e.Logger.Error(err.Error())
return 1
}
if val != *name {
e.Logger.Error("Env Name does not match !!")
return 1
}
e.Logger.Info("Environment(" + *name + ") deletion initiated")
response, err := envClient.DeleteEnv(*name)
if err != nil {
Expand Down
58 changes: 58 additions & 0 deletions internal/command/commands/envtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package commands

import (
"github.com/dream11/odin/internal/backend"
"github.com/dream11/odin/pkg/table"
)

// initiate backend client for environment type
var envTypeClient backend.EnvType

// Env : command declaration
type EnvType command

// Run : implements the actual functionality of the command
func (e *EnvType) Run(args []string) int {

if e.List {
e.Logger.Info("Listing all env type\n")
envTypeList, err := envTypeClient.ListEnvType()
if err != nil {
e.Logger.Error(err.Error())
return 1
}
var tableHeaders []string
var tableData [][]interface{}
tableHeaders = []string{"Env Type"}
for _, envType := range envTypeList {
tableData = append(tableData, []interface{}{
envType,
})
}
table.Write(tableHeaders, tableData)

return 0
}

e.Logger.Error("Not a valid command")
return 127
}

// Help : returns an explanatory string
func (e *EnvType) Help() string {

if e.List {
return commandHelper("list env-type", "env type", "", []Options{})
}

return defaultHelper()
}

// Synopsis : returns a brief helper text for the command's verbs
func (e *EnvType) Synopsis() string {

if e.List {
return "List env types"
}
return defaultHelper()
}
2 changes: 1 addition & 1 deletion internal/command/commands/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (s *Service) Run(args []string) int {
for _, componentStatus := range serviceStatus {
tableData = append(tableData, []interface{}{
componentStatus.Name,
componentStatus.VM,
componentStatus.AWS_EC2,
componentStatus.Container,
})
}
Expand Down

0 comments on commit 053e744

Please sign in to comment.