Module: Meroku::CLI
- Includes:
- Aws::Ec2
- Included in:
- Session
- Defined in:
- lib/meroku/cli.rb,
lib/meroku/cli/help.rb,
lib/meroku/cli/secrets.rb,
lib/meroku/cli/session.rb
Overview
The CLI is used by end users and also maintainers
Defined Under Namespace
Modules: Help, Secrets
Classes: Session
Instance Method Summary
collapse
Methods included from Aws::Ec2
associate_address, #ec2_client, ec2_client, #make_instance, #tag
Instance Method Details
#add_git_remote(name, uri) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/meroku/cli.rb', line 61
def add_git_remote(name, uri)
puts "git remote remove #{name}"
`git remote remove #{name} 2>/dev/null`
puts "git remote add #{name} #{uri}"
`git remote add #{name} #{uri}`
end
|
#apiusername ⇒ Object
57
58
59
|
# File 'lib/meroku/cli.rb', line 57
def apiusername
`cat ~/.meroku/.apiusername.chomp`
end
|
#create ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/meroku/cli.rb', line 44
def create
Meroku::Api::Request.post(
'https://www.meroku.com/apps.json',
app: { name: 'unnamed' }, apisecret: `cat ~/.meroku/.apisecret`.chomp
) do |response|
puts "Created #{response['attributes']['name']}, adding git remote"
add_git_remote(
'meroku',
"#{apiusername}@www.meroku.com:#{response['attributes']['name']}.git"
)
end
end
|
#keys_add ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/meroku/cli.rb', line 68
def keys_add
file = "#{Dir.home}/.ssh/id_rsa.pub"
apisecret = `cat ~/.meroku/.apisecret`.chomp
abort "error: #{file} not found" unless File.exist?(file)
Meroku::Api::Request.post(
'https://www.meroku.com/publickeys.json',
publickey: { name: 'id_rsa.pub', data: `cat ~/.ssh/id_rsa.pub`.chomp },
apisecret: apisecret
) do |response|
puts "Added #{response['attributes']['name']}"
end
end
|
#login ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/meroku/cli.rb', line 23
def login
email, password = Meroku::Extensions.mgets(%i[email password])
Meroku::Api::Request.post(
'https://www.meroku.com/users/sign_in.json',
user: { email: email, password: password }
) do |response|
puts "Signed in as #{response['attributes']['email']}"
save_setting('apiusername', response['attributes']['apiusername'])
save_setting('apisecret', response['attributes']['apisecret'])
end
end
|
#logout ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/meroku/cli.rb', line 35
def logout
[
"#{Dir.home}/.meroku/.apiusername",
"#{Dir.home}/.meroku/.apisecret"
].each do |f|
File.delete(f) if File.exist?(f)
end
end
|
#save_setting(name, value) ⇒ Object
93
94
95
96
|
# File 'lib/meroku/cli.rb', line 93
def save_setting(name, value)
FileUtils.mkdir_p "#{Dir.home}/.meroku"
IO.write("#{Dir.home}/.meroku/.#{name}", value)
end
|
#signup ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/meroku/cli.rb', line 10
def signup
email, pw = Meroku::Extensions.mgets(%i[email password])
Meroku::Api::Request.post(
'https://www.meroku.com/users.json',
user: { email: email, password: pw, password_confirmation: pw }
) do |response|
puts "Signed up #{response['attributes']['email']}"
save_setting('apiusername', response['attributes']['apiusername'])
save_setting('apisecret', response['attributes']['apisecret'])
end
true
end
|
#spawn ⇒ Object
81
82
83
84
85
86
|
# File 'lib/meroku/cli.rb', line 81
def spawn
Meroku::CLI::Secrets.load(admin: true)
node = Meroku::Node.new
node.associate_address.configure_keys.add_sources.ubuntu_updates
node.install_packages.database_inits.git_clone.nginx_configs.start_rails
end
|