Skip to content

Commit

Permalink
Merge pull request #129 from dream11/development
Browse files Browse the repository at this point in the history
Release 1.2.0-beta
  • Loading branch information
akshaypatidar1999 authored Jul 25, 2022
2 parents 60f167b + 0a218e8 commit 67f7a04
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 81 deletions.
1 change: 1 addition & 0 deletions api/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ type Configuration struct {
Keys SecretKeys
AccessToken string `yaml:"access_token,omitempty" json:"access_token,omitempty"`
RefreshToken string `yaml:"refresh_token,omitempty" json:"refresh_token,omitempty"`
EnvName string `yaml:"envName,omitempty" json:"envName:,omitempty"`
}
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-alpha",
Version: "1.2.0-beta",
}
44 changes: 2 additions & 42 deletions internal/backend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package backend

import (
"encoding/json"
"fmt"
"path"

"github.com/dream11/odin/api/service"
Expand All @@ -14,28 +13,12 @@ type Service struct{}
// root entity
var serviceEntity = "services"

// CreateService : register a service version with backend
func (s *Service) CreateService(service interface{}) {
client := newApiClient()

response := client.actionWithRetry(serviceEntity+"/", "POST", service)
response.Process(true) // process response and exit if error
}

func (s *Service) CreateServiceStream(serviceDefinition interface{}, provisioningConfigMap map[string]interface{}) {
client := newStreamingApiClient()
response := client.stream(serviceEntity+"/", "POST", service.MergedService{Service: serviceDefinition, ProvisioningConfig: provisioningConfigMap})
response.Process(true) // process response and exit if error
}

// RebuildService : rebuild a service
func (s *Service) RebuildService(service, version string) {
client := newApiClient()

response := client.actionWithRetry(path.Join(serviceEntity, service, "versions", version, "rebuild")+"/", "PUT", nil)
response.Process(true)
}

// RebuildServiceStream : rebuild a service using streams
func (s *Service) RebuildServiceStream(service, version string) {
client := newStreamingApiClient()
Expand Down Expand Up @@ -75,15 +58,6 @@ func (s *Service) ListServices(team, version, serviceName string, label string)
return serviceResponse.Response, err
}

// UndeployService : To remove a service from a given env
func (s *Service) UndeployService(serviceName, envName string) {
client := newApiClient()
client.QueryParams["env_name"] = envName

response := client.actionWithRetry(path.Join(serviceEntity, "undeploy", serviceName)+"/", "DELETE", nil)
response.Process(true)
}

// UnDeployServiceStream : un-deploy a service in an Env and stream creation events
func (s *Service) UnDeployServiceStream(serviceName, envName string) {
client := newStreamingApiClient()
Expand Down Expand Up @@ -128,11 +102,9 @@ func (s *Service) UnlabelService(service, version, label string) {
}

// DeployServiceStream : deploy a service in an Env and stream creation events
func (s *Service) DeployReleasedServiceStream(service, version, env, configStoreNamespace string, force, rebuild bool, provisionConfig interface{}) {
func (s *Service) DeployReleasedServiceStream(service, version, env, configStoreNamespace string, provisionConfig interface{}) {
client := newStreamingApiClient()
client.QueryParams["env_name"] = env
client.QueryParams["force"] = fmt.Sprintf("%v", force)
client.QueryParams["rebuild"] = fmt.Sprintf("%v", rebuild)
client.QueryParams["config_store_namespace"] = configStoreNamespace

data := map[string]interface{}{}
Expand All @@ -146,11 +118,9 @@ func (s *Service) DeployReleasedServiceStream(service, version, env, configStore
}

// DeployServiceStream : deploy a service in an Env and stream creation events
func (s *Service) DeployUnreleasedServiceStream(serviceDefinition, provisionConfig interface{}, env, configStoreNamespace string, force, rebuild bool) {
func (s *Service) DeployUnreleasedServiceStream(serviceDefinition, provisionConfig interface{}, env, configStoreNamespace string) {
client := newStreamingApiClient()
client.QueryParams["env_name"] = env
client.QueryParams["force"] = fmt.Sprintf("%v", force)
client.QueryParams["rebuild"] = fmt.Sprintf("%v", rebuild)
client.QueryParams["config_store_namespace"] = configStoreNamespace

data := map[string]interface{}{
Expand All @@ -165,16 +135,6 @@ func (s *Service) DeployUnreleasedServiceStream(serviceDefinition, provisionConf
response.Process(true)
}

func (s *Service) BuildAndDeployServiceStream(serviceDefinition interface{}, env, configStoreNamespace, serviceName, serviceVersion string) {
client := newStreamingApiClient()
client.QueryParams["env_name"] = env
client.QueryParams["service_name"] = serviceName
client.QueryParams["service_version"] = serviceVersion
client.QueryParams["config_store_namespace"] = configStoreNamespace
response := client.stream(path.Join(serviceEntity, "builddeploy")+"/", "POST", serviceDefinition)
response.Process(true)
}

// StatusService : get status of a service
func (s *Service) StatusService(serviceName, version string) ([]service.Status, error) {
client := newApiClient()
Expand Down
3 changes: 3 additions & 0 deletions internal/command/command_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func CommandsCatalog() map[string]cli.CommandFactory {
"status env": func() (cli.Command, error) {
return &commands.Env{Status: true}, nil
},
"set env": func() (cli.Command, error) {
return &commands.Env{Set: true}, nil
},

// Verbs for `component-type` resource
"list component-type": func() (cli.Command, error) {
Expand Down
1 change: 1 addition & 0 deletions internal/command/commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type command struct {
Generate bool // Generate resources
Unlabel bool // Unlabel a resource
Release bool // Release a resource record
Set bool // Set a default env

Logger ui.Logger // Use this to log messages
Input ui.Input // Use this to take inputs
Expand Down
28 changes: 13 additions & 15 deletions internal/command/commands/componentType.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,20 @@ func (c *ComponentType) Run(args []string) int {
}

c.Logger.Output(fmt.Sprintf("\n%s", details))
/*
var tableHeaders []string
var tableData [][]interface{}
if len(componentDetailsResponse.ExposedConfigs) > 0 {
tableHeaders = []string{"Config", "Mandatory", "Data Type"}
for _, exposed_config := range componentDetailsResponse.ExposedConfigs {
tableData = append(tableData, []interface{}{
exposed_config.Config,
exposed_config.Mandatory,
exposed_config.DataType,
})
}
var tableHeaders []string
var tableData [][]interface{}
if len(componentDetailsResponse.ExposedConfigs) > 0 {
tableHeaders = []string{"Config", "Mandatory", "Data Type"}
for _, exposed_config := range componentDetailsResponse.ExposedConfigs {
tableData = append(tableData, []interface{}{
exposed_config.Config,
exposed_config.Mandatory,
exposed_config.DataType,
})
}
c.Logger.ItalicEmphasize("\nList of exposed configs :\n")
table.Write(tableHeaders, tableData)
*/
}
c.Logger.ItalicEmphasize("\nList of exposed configs :\n")
table.Write(tableHeaders, tableData)
return 0
}

Expand Down
44 changes: 42 additions & 2 deletions internal/command/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/dream11/odin/internal/backend"
"github.com/dream11/odin/pkg/datetime"
"github.com/dream11/odin/pkg/table"
"github.com/dream11/odin/pkg/utils"
"gopkg.in/yaml.v3"
)

Expand All @@ -18,6 +19,8 @@ var envClient backend.Env
// Env : command declaration
type Env command

const ENV_NAME_KEY = "EnvName"

// Run : implements the actual functionality of the command
func (e *Env) Run(args []string) int {
// Define flag set
Expand Down Expand Up @@ -47,7 +50,8 @@ func (e *Env) Run(args []string) int {
}

envClient.CreateEnvStream(envConfig)

e.Logger.Output("Command to set default Env. Once you do this, no need to pass --env everytime.")
e.Logger.ItalicEmphasize("odin set env --name <envName>")
return 0
}

Expand All @@ -57,6 +61,9 @@ func (e *Env) Run(args []string) int {
}

if e.Status {
if *name == "" {
*name = utils.FetchKey(ENV_NAME_KEY)
}
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {

Expand Down Expand Up @@ -119,6 +126,9 @@ func (e *Env) Run(args []string) int {
}

if e.Describe {
if *name == "" {
*name = utils.FetchKey(ENV_NAME_KEY)
}
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
e.Logger.Info("Describing " + *name)
Expand Down Expand Up @@ -172,6 +182,9 @@ func (e *Env) Run(args []string) int {
}

if e.Delete {
if *name == "" {
*name = utils.FetchKey(ENV_NAME_KEY)
}
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
e.Logger.Info("Environment(" + *name + ") deletion initiated")
Expand All @@ -189,7 +202,9 @@ func (e *Env) Run(args []string) int {
}

if e.DescribeHistory {

if *name == "" {
*name = utils.FetchKey(ENV_NAME_KEY)
}
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
if *id == 0 {
Expand Down Expand Up @@ -247,6 +262,21 @@ func (e *Env) Run(args []string) int {
return 1
}

if e.Set {
emptyParameters := emptyParameters(map[string]string{"--name": *name})
if len(emptyParameters) == 0 {
err := utils.SetEnv(*name)
if err != nil {
e.Logger.Error(err.Error())
return 1
}
e.Logger.Output(fmt.Sprintf("Default environment has been set to %s", *name))
return 0
}
e.Logger.Error(fmt.Sprintf("%s cannot be blank", emptyParameters))
return 1
}

e.Logger.Error("Not a valid command")
return 127
}
Expand Down Expand Up @@ -297,6 +327,12 @@ func (e *Env) Help() string {
})
}

if e.Set {
return commandHelper("set", "environment", "", []Options{
{Flag: "--name", Description: "name of environment"},
})
}

return defaultHelper()
}

Expand Down Expand Up @@ -325,5 +361,9 @@ func (e *Env) Synopsis() string {
if e.Status {
return "Fetch deployment status of the environment"
}

if e.Set {
return "Set a default env"
}
return defaultHelper()
}
Loading

0 comments on commit 67f7a04

Please sign in to comment.