Class: Minfra::Cli::Stack

Inherits:
Command show all
Defined in:
lib/minfra/cli/commands/stack.rb

Instance Method Summary collapse

Methods included from Logging

#debug, #deprecated, #error, #exit_error, #info, #warn

Methods included from Common

#run_cmd

Instance Method Details

#app(stack_name) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/minfra/cli/commands/stack.rb', line 72

def app(stack_name)
  cluster = nil
  deployment = nil
  template = Minfra::Cli::StackM::AppTemplate.new(stack_name, minfra_config)
  template.read
  puts "Template: #{template.app_path}\n#{template}"
  apps = AppResource.all(filter: { identifier: template.app.identifier }).data
  if apps.empty?
    puts 'Auth: app uninstalled'
    atts = {
      identifier: template.app.identifier,
      name: template.app.name,
      short_name: template.app.short_name,
      description: template.app.description,
      native: template.app.native,
      start_url: template.app.start_url,
      public: template.app.public
    }
    app_res = AppResource.build({ data: { attributes: atts, type: 'apps' } })
    app_res.save
    app = app_res.data
  else
    app = apps.first
  end
  puts "Auth: app installed #{app.id}"

  clients = OauthClientResource.all(filter: { app_id: app.id }).data
  if clients.empty?
    puts 'Auth: client not registered'
    atts = { redirect_uris: template.client.redirect_uris.map { |r| "#{app.start_url}#{r}" },
             native: template.client.native, ppid: template.client.ppid, name: template.client.name, app_id: app.id }
    client_res = OauthClientResource.build({ data: { attributes: atts, type: 'oauth_clients' } })
    client_res.save
    client = client_res.data
  else
    client = clients.first
  end
  puts "Auth: client registered #{client.id}"

  client_template = Minfra::Cli::StackM::ClientTemplate.new(stack_name, client.name, minfra_config)
  return if client_template.exist?

  File.write(client_template.path.to_s,
             { name: client.name, identifier: client.identifier, secret: client.secret }.to_json)

  # TODO: create app configuration
  # TODO: create provider
end

#dashboard(stack_name = 'all') ⇒ Object



21
22
23
# File 'lib/minfra/cli/commands/stack.rb', line 21

def dashboard(stack_name = 'all')
  kube.dashboard(stack_name, options[:environment], options[:deployment], options[:cluster])
end

#deploy(stack_name, message = '') ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/minfra/cli/commands/stack.rb', line 35

def deploy(stack_name, message = '')
  stacks = l('env.stacks') || []
  default_stacks = minfra_config.project.default_stacks || []
  stacks += default_stacks
  if stacks.include?(stack_name) || options[:force] || options[:test]
    kube.deploy(stack_name, message)
  else
    exit_error("project:default_stacks or hiera:env.stacks has to include '#{stack_name}' or use --force or --test")
  end
end

#describeObject



13
14
15
# File 'lib/minfra/cli/commands/stack.rb', line 13

def describe
  pp minfra_config.describe(options['environment'])
end

#destroy(stack_name) ⇒ Object



59
60
61
# File 'lib/minfra/cli/commands/stack.rb', line 59

def destroy(stack_name)
  kube.destroy(stack_name)
end

#listObject



66
67
68
# File 'lib/minfra/cli/commands/stack.rb', line 66

def list
  kube.list
end

#rollback(*_args) ⇒ Object



50
51
52
53
54
# File 'lib/minfra/cli/commands/stack.rb', line 50

def rollback(*_args)
  warn 'needs implementation'
  exit 1
  # kube.rollback(stack_name, options[:environment], options[:deployment], options[:cluster], args)
end