Class: Nvoi::Cli::Config::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/nvoi/cli/config/command.rb

Overview

Command helper for all config operations Uses CredentialStore for crypto, Configuration::Builder for transformations

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Command

Returns a new instance of Command.



9
10
11
12
# File 'lib/nvoi/cli/config/command.rb', line 9

def initialize(options)
  @options = options
  @working_dir = options[:dir] || "."
end

Instance Method Details

#app_rm(name) ⇒ Object



100
101
102
103
104
# File 'lib/nvoi/cli/config/command.rb', line 100

def app_rm(name)
  with_config do |builder|
    builder.remove_app(name)
  end
end

#app_set(name, servers:, **opts) ⇒ Object

App



94
95
96
97
98
# File 'lib/nvoi/cli/config/command.rb', line 94

def app_set(name, servers:, **opts)
  with_config do |builder|
    builder.app_entry(name, servers:, **opts)
  end
end

#database_rmObject



113
114
115
116
117
# File 'lib/nvoi/cli/config/command.rb', line 113

def database_rm
  with_config do |builder|
    builder.remove_database
  end
end

#database_set(servers:, adapter:, **opts) ⇒ Object

Database



107
108
109
110
111
# File 'lib/nvoi/cli/config/command.rb', line 107

def database_set(servers:, adapter:, **opts)
  with_config do |builder|
    builder.database(servers:, adapter:, **opts)
  end
end

#domain_rmObject



48
49
50
51
52
# File 'lib/nvoi/cli/config/command.rb', line 48

def domain_rm
  with_config do |builder|
    builder.remove_domain_provider
  end
end

#domain_set(provider, api_token:, account_id:) ⇒ Object

Domain provider



42
43
44
45
46
# File 'lib/nvoi/cli/config/command.rb', line 42

def domain_set(provider, api_token:, account_id:)
  with_config do |builder|
    builder.domain_provider(provider, api_token:, account_id:)
  end
end

#env_rm(key_name) ⇒ Object



152
153
154
155
156
# File 'lib/nvoi/cli/config/command.rb', line 152

def env_rm(key_name)
  with_config do |builder|
    builder.remove_env(key_name)
  end
end

#env_set(key_name, value) ⇒ Object

Env



146
147
148
149
150
# File 'lib/nvoi/cli/config/command.rb', line 146

def env_set(key_name, value)
  with_config do |builder|
    builder.env(key_name, value)
  end
end

#init(name, environment) ⇒ Object

Initialize new config



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nvoi/cli/config/command.rb', line 15

def init(name, environment)
  result = Configuration::Builder.init(name:, environment:)

  if result.failure?
    error("Failed to initialize: #{result.error_message}")
    return
  end

  # Write encrypted config
  config_path = File.join(@working_dir, Utils::DEFAULT_ENCRYPTED_FILE)
  key_path = File.join(@working_dir, Utils::DEFAULT_KEY_FILE)

  File.binwrite(config_path, result.config)
  File.write(key_path, "#{result.master_key}\n", perm: 0o600)

  update_gitignore

  success("Created #{Utils::DEFAULT_ENCRYPTED_FILE}")
  success("Created #{Utils::DEFAULT_KEY_FILE} (keep safe, never commit)")
  puts
  puts "Next steps:"
  puts "  nvoi config domain set cloudflare --api-token=TOKEN --account-id=ID"
  puts "  nvoi config provider set hetzner --api-token=TOKEN --server-type=cx22 --location=fsn1"
  puts "  nvoi config server set web --master"
end

#provider_rmObject



61
62
63
64
65
# File 'lib/nvoi/cli/config/command.rb', line 61

def provider_rm
  with_config do |builder|
    builder.remove_compute_provider
  end
end

#provider_set(provider, **opts) ⇒ Object

Compute provider



55
56
57
58
59
# File 'lib/nvoi/cli/config/command.rb', line 55

def provider_set(provider, **opts)
  with_config do |builder|
    builder.compute_provider(provider, **opts)
  end
end

#secret_rm(key_name) ⇒ Object



139
140
141
142
143
# File 'lib/nvoi/cli/config/command.rb', line 139

def secret_rm(key_name)
  with_config do |builder|
    builder.remove_secret(key_name)
  end
end

#secret_set(key_name, value) ⇒ Object

Secret



133
134
135
136
137
# File 'lib/nvoi/cli/config/command.rb', line 133

def secret_set(key_name, value)
  with_config do |builder|
    builder.secret(key_name, value)
  end
end

#server_rm(name) ⇒ Object



74
75
76
77
78
# File 'lib/nvoi/cli/config/command.rb', line 74

def server_rm(name)
  with_config do |builder|
    builder.remove_server(name)
  end
end

#server_set(name, master: false, type: nil, location: nil, count: 1) ⇒ Object

Server



68
69
70
71
72
# File 'lib/nvoi/cli/config/command.rb', line 68

def server_set(name, master: false, type: nil, location: nil, count: 1)
  with_config do |builder|
    builder.server(name, master:, type:, location:, count:)
  end
end

#service_rm(name) ⇒ Object



126
127
128
129
130
# File 'lib/nvoi/cli/config/command.rb', line 126

def service_rm(name)
  with_config do |builder|
    builder.remove_service(name)
  end
end

#service_set(name, servers:, image:, **opts) ⇒ Object

Service



120
121
122
123
124
# File 'lib/nvoi/cli/config/command.rb', line 120

def service_set(name, servers:, image:, **opts)
  with_config do |builder|
    builder.service(name, servers:, image:, **opts)
  end
end

#volume_rm(server, name) ⇒ Object



87
88
89
90
91
# File 'lib/nvoi/cli/config/command.rb', line 87

def volume_rm(server, name)
  with_config do |builder|
    builder.remove_volume(server, name)
  end
end

#volume_set(server, name, size: 10) ⇒ Object

Volume



81
82
83
84
85
# File 'lib/nvoi/cli/config/command.rb', line 81

def volume_set(server, name, size: 10)
  with_config do |builder|
    builder.volume(server, name, size:)
  end
end