kanrisuru 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +17 -0
- data/.rubocop.yml +47 -0
- data/.rubocop_todo.yml +0 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +2 -5
- data/LICENSE.txt +1 -1
- data/README.md +143 -7
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/kanrisuru.gemspec +21 -12
- data/lib/kanrisuru.rb +41 -2
- data/lib/kanrisuru/command.rb +99 -0
- data/lib/kanrisuru/core.rb +53 -0
- data/lib/kanrisuru/core/archive.rb +154 -0
- data/lib/kanrisuru/core/disk.rb +302 -0
- data/lib/kanrisuru/core/file.rb +332 -0
- data/lib/kanrisuru/core/find.rb +108 -0
- data/lib/kanrisuru/core/group.rb +97 -0
- data/lib/kanrisuru/core/ip.rb +1032 -0
- data/lib/kanrisuru/core/mount.rb +138 -0
- data/lib/kanrisuru/core/path.rb +140 -0
- data/lib/kanrisuru/core/socket.rb +168 -0
- data/lib/kanrisuru/core/stat.rb +104 -0
- data/lib/kanrisuru/core/stream.rb +121 -0
- data/lib/kanrisuru/core/system.rb +348 -0
- data/lib/kanrisuru/core/transfer.rb +203 -0
- data/lib/kanrisuru/core/user.rb +198 -0
- data/lib/kanrisuru/logger.rb +8 -0
- data/lib/kanrisuru/mode.rb +277 -0
- data/lib/kanrisuru/os_package.rb +235 -0
- data/lib/kanrisuru/remote.rb +10 -0
- data/lib/kanrisuru/remote/cluster.rb +95 -0
- data/lib/kanrisuru/remote/cpu.rb +68 -0
- data/lib/kanrisuru/remote/env.rb +33 -0
- data/lib/kanrisuru/remote/file.rb +354 -0
- data/lib/kanrisuru/remote/fstab.rb +412 -0
- data/lib/kanrisuru/remote/host.rb +191 -0
- data/lib/kanrisuru/remote/memory.rb +19 -0
- data/lib/kanrisuru/remote/os.rb +87 -0
- data/lib/kanrisuru/result.rb +78 -0
- data/lib/kanrisuru/template.rb +32 -0
- data/lib/kanrisuru/util.rb +40 -0
- data/lib/kanrisuru/util/bits.rb +203 -0
- data/lib/kanrisuru/util/fs_mount_opts.rb +655 -0
- data/lib/kanrisuru/util/os_family.rb +213 -0
- data/lib/kanrisuru/util/signal.rb +161 -0
- data/lib/kanrisuru/version.rb +3 -1
- data/spec/functional/core/archive_spec.rb +228 -0
- data/spec/functional/core/disk_spec.rb +80 -0
- data/spec/functional/core/file_spec.rb +341 -0
- data/spec/functional/core/find_spec.rb +52 -0
- data/spec/functional/core/group_spec.rb +65 -0
- data/spec/functional/core/ip_spec.rb +71 -0
- data/spec/functional/core/path_spec.rb +93 -0
- data/spec/functional/core/socket_spec.rb +31 -0
- data/spec/functional/core/stat_spec.rb +98 -0
- data/spec/functional/core/stream_spec.rb +99 -0
- data/spec/functional/core/system_spec.rb +96 -0
- data/spec/functional/core/transfer_spec.rb +108 -0
- data/spec/functional/core/user_spec.rb +76 -0
- data/spec/functional/os_package_spec.rb +75 -0
- data/spec/functional/remote/cluster_spec.rb +45 -0
- data/spec/functional/remote/cpu_spec.rb +41 -0
- data/spec/functional/remote/env_spec.rb +36 -0
- data/spec/functional/remote/fstab_spec.rb +76 -0
- data/spec/functional/remote/host_spec.rb +68 -0
- data/spec/functional/remote/memory_spec.rb +29 -0
- data/spec/functional/remote/os_spec.rb +63 -0
- data/spec/functional/remote/remote_file_spec.rb +180 -0
- data/spec/helper/test_hosts.rb +68 -0
- data/spec/hosts.json +92 -0
- data/spec/spec_helper.rb +11 -3
- data/spec/unit/fstab_spec.rb +22 -0
- data/spec/unit/kanrisuru_spec.rb +9 -0
- data/spec/unit/mode_spec.rb +183 -0
- data/spec/unit/template_spec.rb +13 -0
- data/spec/unit/util_spec.rb +177 -0
- data/spec/zz_reboot_spec.rb +46 -0
- metadata +136 -13
- data/spec/kanrisuru_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c85c69fa5f91368ab9857bfd7124a05516f3e3e6d224d2bd889a2334d93fe67f
|
4
|
+
data.tar.gz: 43ead0d9b608199c14ee204c1f9dfc3910342138a8db211a2b7e62d3e6bad372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95fa98ff75efa98e2faaea0656500f063b39721ba2535e3027581b1844571621b5d3ee9ad11787439d74dfedb80aee053ff8f32a7733c902a7535870921d7da
|
7
|
+
data.tar.gz: 2ec71eec8b97ee92122d295bb5d736c9b44991cd134c4dce7c0b29e9e84462cb54997ece06d3ea5c8ca384d5221d4a9f4136223c60391888217f326f212343c1
|
data/.gitignore
CHANGED
@@ -9,3 +9,20 @@
|
|
9
9
|
|
10
10
|
# rspec failure tracking
|
11
11
|
.rspec_status
|
12
|
+
.Gemfile
|
13
|
+
.byebug_history
|
14
|
+
.ruby-version
|
15
|
+
|
16
|
+
*.gem
|
17
|
+
coverage/*
|
18
|
+
Gemfile.lock
|
19
|
+
*~
|
20
|
+
.bundle
|
21
|
+
.rvmrc
|
22
|
+
log/*
|
23
|
+
measurement/*
|
24
|
+
pkg/*
|
25
|
+
.DS_Store
|
26
|
+
.env
|
27
|
+
spec/dummy/tmp/*
|
28
|
+
spec/dummy/log/*.log
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
NewCops: enable
|
5
|
+
SuggestExtensions: false
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/CyclomaticComplexity:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/PerceivedComplexity:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/ClassLength:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/ModuleLength:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/BlockLength:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Lint/ConstantDefinitionInBlock:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
RSpec/FilePath:
|
35
|
+
SpecSuffixOnly: true
|
36
|
+
|
37
|
+
RSpec/ExampleLength:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
RSpec/MultipleExpectations:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
RSpec/BeforeAfterAll:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
RSpec/LeakyConstantDeclaration:
|
47
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
File without changes
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
[](https://rubygems.org/gems/kanrisuru)
|
2
|
+
[](https://github.com/avamia/kanrisuru/blob/main/LICENSE.txt)
|
3
|
+

|
4
|
+
|
1
5
|
# Kanrisuru
|
2
6
|
|
3
|
-
|
7
|
+
Kanrisuru (manage) helps you remotely control infrastructure using Ruby. This is done over SSH. I'm working on building up some basic functionality to help quickly provision, deploy and manage a single host or cluster of hosts.
|
8
|
+
|
9
|
+
The idea behind this project is not to replace the numerous other projects to manage your infrastrucutre, however, I've found there usually meant to be a standalone project that have their own ecosystem. With Kanrisuru, you essentailly plug the library directly into your ruby project.
|
4
10
|
|
5
|
-
|
11
|
+
At this point, Kanrisuru doesn't use a DSL, or offer idempotency, and while that may be added later on, the goal with this project is to expose helpful ways of managing your remote infrastructure with plain ruby in a procedural manner. The realization I had was when trying to deal with other open source projects, you either had to deal with a different language than ruby, use agents on remote hosts, or deal with a complex library that is meant to act in a declarative manner.
|
12
|
+
|
13
|
+
If you want to dynamically interact with a host, eg: If you need to dynamically scale your infrastructure by continually monitoring specific stats from a centralized system, Kanrisuru can help you accomplish this.
|
6
14
|
|
7
15
|
## Installation
|
8
16
|
|
@@ -22,18 +30,146 @@ Or install it yourself as:
|
|
22
30
|
|
23
31
|
## Usage
|
24
32
|
|
25
|
-
|
33
|
+
Run basic commands you would have access to while running on a remote host or on a cluster of hosts.
|
34
|
+
|
35
|
+
### Host
|
36
|
+
```ruby
|
37
|
+
host = Kanrisuru::Remote::Host.new(host: 'host', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
|
38
|
+
result = host.whoami
|
39
|
+
result.to_s # => 'ubuntu'
|
40
|
+
|
41
|
+
result = host.pwd
|
42
|
+
result.path # => /home/ubuntu
|
43
|
+
```
|
44
|
+
|
45
|
+
### Cluster
|
46
|
+
```ruby
|
47
|
+
cluster = Kanrisuru::Remote::Cluster.new([{
|
48
|
+
host: 'host1', username: 'ubuntu', keys: ['~/.ssh/id_rsa']
|
49
|
+
}, {
|
50
|
+
host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']
|
51
|
+
})
|
52
|
+
|
53
|
+
cluster.whoami # => {host: 'host1', result: 'ubuntu'}, {host: 'host2', result: 'alice'}
|
54
|
+
cluster.pwd # => {host: 'host1', result: '/home/ubuntu'}, {host: 'host2', result: '/home/alice'}
|
55
|
+
|
56
|
+
cluster.each do |host|
|
57
|
+
host.pwd.path # => /home/ubuntu
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
### Host or Cluster with underlying command
|
62
|
+
```ruby
|
63
|
+
host = Kanrisuru::Remote::Host.new(host: 'host1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
|
64
|
+
|
65
|
+
command = Kanrisuru::Command.new('uname')
|
66
|
+
host.execute(command)
|
67
|
+
|
68
|
+
command.success? #=> true
|
69
|
+
command.to_s #=> Linux
|
70
|
+
|
71
|
+
cluster = Kanrisuru::Remote::Cluster.new([host, {host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']}])
|
72
|
+
|
73
|
+
cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', result: 'Linux'}
|
74
|
+
```
|
75
|
+
|
76
|
+
## Methods and Testing
|
77
|
+
|
78
|
+
| Description | Ruby | Shell | Module | Man | Debian | Ubuntu | Fedora | Centos | RHEL | openSUSE | SLES |
|
79
|
+
|---------------------------------------|------------------|--------------------|--------|--------------------------------------|--------|--------|--------|--------|------|----------|------|
|
80
|
+
| **System** | | | | | | | | | | | |
|
81
|
+
| Get CPU Info | cpu_info | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
82
|
+
| Get Load Average | load_average | cat /proc/load_avg | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
83
|
+
| Get RAM Available | free | cat /proc/meminfo | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
84
|
+
| Get list of processes | ps | ps | core | https://linux.die.net/man/1/ps | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
85
|
+
| Get Env vars | load_env | env | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
86
|
+
| Kill process | kill | kill | core | https://linux.die.net/man/1/kill | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
87
|
+
| Get uptime of system | uptime | cat /proc/uptime | core | https://linux.die.net/man/1/uptime | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
88
|
+
| Get who's logged in | w | w | core | https://linux.die.net/man/1/w | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
89
|
+
| Reboot machine | reboot | shutdown | core | https://linux.die.net/man/8/reboot | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
90
|
+
| Poweroff machine | poweroff | shutdown | core | https://linux.die.net/man/8/shutdown | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
91
|
+
| **Disk** | | | | | | | | | | | |
|
92
|
+
| Get Disk Space | df | df | core | https://linux.die.net/man/1/df | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
93
|
+
| Get Disk Usage | du | du | core | https://linux.die.net/man/1/du | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
94
|
+
| List block devices | lsblk | lsblk | core | https://linux.die.net/man/8/lsblk | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
95
|
+
| Get block device attributes | blkid | blikd | core | https://linux.die.net/man/8/blkid | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
96
|
+
| **Mount** | | | | | | | | | | | |
|
97
|
+
| Mount a filesystem | mount | mount | core | https://linux.die.net/man/8/mount | | | | | | | |
|
98
|
+
| Unmount a filesystem | umount | umount | core | https://linux.die.net/man/8/umount | | | | | | | |
|
99
|
+
| **Group** | | | | | | | | | | | |
|
100
|
+
| Get Group Id | get_gid | getent group | core | https://linux.die.net/man/1/getent | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
101
|
+
| Get Group | get_group | grep /etc/group | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
102
|
+
| Create Group | create_group | groupadd | core | https://linux.die.net/man/8/groupadd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
103
|
+
| Update Group | update_group | groupmod | core | https://linux.die.net/man/8/groupmod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
104
|
+
| Delete Group | delete_group | groupdel | core | https://linux.die.net/man/8/groupdel | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
105
|
+
| **User** | | | | | | | | | | | |
|
106
|
+
| Get User Id | get_uid | id -u | core | https://linux.die.net/man/1/id | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
107
|
+
| Get User | get_user | id | core | https://linux.die.net/man/1/id | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
108
|
+
| Create User | create_user | useradd | core | https://linux.die.net/man/8/useradd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
109
|
+
| Update User | update_user | usermod | core | https://linux.die.net/man/8/usermod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
110
|
+
| Delete User | delete_user | userdel | core | https://linux.die.net/man/8/userdel | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
111
|
+
| **Path** | | | | | | | | | | | |
|
112
|
+
| List files and directories | ls | ls | core | https://linux.die.net/man/1/ls | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
113
|
+
| Get Current Dir | pwd | pwd | core | https://linux.die.net/man/1/pwd | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
114
|
+
| Get Current User | whoami | whoami | core | https://linux.die.net/man/1/whoami | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
115
|
+
| Get Full Path of Shell Command | which | which | core | https://linux.die.net/man/1/which | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
116
|
+
| Real Path | realpath | realpath | core | https://linux.die.net/man/1/realpath | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
117
|
+
| Read link | readlink | readlink | core | https://linux.die.net/man/1/readlink | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
118
|
+
| Change Dir | cd | cd | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
119
|
+
| **File** | | | | | | | | | | | |
|
120
|
+
| "Find file, dir, special file device" | find | find | core | https://linux.die.net/man/1/find | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
121
|
+
| Stat file info | stat | stat | core | https://linux.die.net/man/1/stat | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
122
|
+
| Change Permission of file / folder | chmod | chmod | core | https://linux.die.net/man/1/chmod | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
123
|
+
| Change Ownership of file / folder | chown | chown | core | https://linux.die.net/man/1/chown | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
124
|
+
| Hard Link File | ln | ln | core | https://linux.die.net/man/1/ln | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
125
|
+
| Soft Link File / Dir | ln_s | ln | core | https://linux.die.net/man/1/ln | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
126
|
+
| Create Directory | mkdir | mkdir | core | https://linux.die.net/man/1/mkdir | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
127
|
+
| Remove file / directory | rm | rm | core | https://linux.die.net/man/1/rm | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
128
|
+
| Remove Directory | rmdir | rm | core | https://linux.die.net/man/1/rm | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
129
|
+
| Touch File | touch | touch | core | https://linux.die.net/man/1/touch | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
130
|
+
| Copy file / directory | cp | cp | core | https://linux.die.net/man/1/cp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
131
|
+
| Move file / directory | mv | mv | core | https://linux.die.net/man/1/mv | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
132
|
+
| "Get file line, word, and char count" | wc | wc | core | https://linux.die.net/man/1/wc | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
133
|
+
| **Stream** | | | | | | | | | | | |
|
134
|
+
| Get content from beginning of file | head | head | core | https://linux.die.net/man/1/head | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
135
|
+
| Get content from end of file | tail | tail | core | https://linux.die.net/man/1/tail | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
136
|
+
| Read a chunk from a file by lines | reach_file_chunk | tail and head | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
137
|
+
| Echo to stdout or to file | echo | echo | core | https://linux.die.net/man/1/echo | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
138
|
+
| Get all content from a file | cat | cat | core | https://linux.die.net/man/1/cat | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
139
|
+
| Sed | sed | sed | core | https://linux.die.net/man/1/sed | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
140
|
+
| **Archive** | | | | | | | | | | | |
|
141
|
+
| Tar Files | tar | tar | core | https://linux.die.net/man/1/tar | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
142
|
+
| **Network** | | | | | | | | | | | |
|
143
|
+
| Manage network devices | ip | ip | core | https://linux.die.net/man/8/ip | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
144
|
+
| Get Socket Details | ss | ss | core | https://linux.die.net/man/8/ss | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
145
|
+
| **Transfer** | | | | | | | | | | | |
|
146
|
+
| Upload to remote server | upload | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
147
|
+
| Download from remote server | download | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
148
|
+
| Wget | wget | wget | core | https://linux.die.net/man/1/wget | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
26
149
|
|
27
150
|
## Development
|
28
151
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies.
|
152
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
153
|
+
|
154
|
+
|
155
|
+
To test kanrisuru across various linux distros, update your local `/etc/hosts` file to create an alias to the local virtual machine with that distro type. You can also set the host alias to the localhost machine.
|
156
|
+
|
157
|
+
To select which hosts to run rspec across, prepend the command line or export the variable while running rspec.
|
158
|
+
|
159
|
+
```bash
|
160
|
+
HOSTS=ubuntu,debian,centos rspec
|
161
|
+
```
|
162
|
+
|
163
|
+
This will run tests on the ubuntu, debian and centos instances.
|
164
|
+
|
165
|
+
|
166
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
167
|
|
31
168
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
169
|
|
33
170
|
## Contributing
|
34
171
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/avamia
|
36
|
-
|
172
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/avamia/kanrisuru. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/avamia/kanrisuru/blob/master/CODE_OF_CONDUCT.md).
|
37
173
|
|
38
174
|
## License
|
39
175
|
|
@@ -41,4 +177,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
177
|
|
42
178
|
## Code of Conduct
|
43
179
|
|
44
|
-
Everyone interacting in the Kanrisuru project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/avamia
|
180
|
+
Everyone interacting in the Kanrisuru project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/avamia/kanrisuru/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'kanrisuru'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "kanrisuru"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start(__FILE__)
|
data/kanrisuru.gemspec
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path('lib/kanrisuru/version', __dir__)
|
2
4
|
|
3
5
|
Gem::Specification.new do |gem|
|
4
|
-
gem.name =
|
6
|
+
gem.name = 'kanrisuru'
|
5
7
|
gem.version = Kanrisuru::VERSION
|
6
|
-
gem.
|
7
|
-
gem.email =
|
8
|
-
gem.license =
|
8
|
+
gem.author = 'Ryan Mammina'
|
9
|
+
gem.email = 'ryan@avamia.com'
|
10
|
+
gem.license = 'MIT'
|
11
|
+
gem.summary = 'Manage remote servers with ruby.'
|
12
|
+
gem.homepage = 'https://github.com/avamia/kanrisuru'
|
13
|
+
|
14
|
+
gem.required_ruby_version = '>= 2.5.0'
|
15
|
+
gem.required_rubygems_version = '>= 1.8.11'
|
9
16
|
|
10
|
-
gem.
|
11
|
-
gem.
|
17
|
+
gem.add_development_dependency 'rspec'
|
18
|
+
gem.add_development_dependency 'rubocop'
|
19
|
+
gem.add_development_dependency 'rubocop-rspec'
|
20
|
+
gem.add_development_dependency 'simplecov'
|
12
21
|
|
13
|
-
gem.
|
14
|
-
|
22
|
+
gem.add_runtime_dependency 'net-ping'
|
15
23
|
gem.add_runtime_dependency 'net-scp'
|
16
|
-
gem.add_runtime_dependency 'net-sftp'
|
17
24
|
gem.add_runtime_dependency 'net-ssh'
|
18
25
|
|
19
26
|
gem.files = `git ls-files`.split("\n")
|
20
|
-
gem.require_paths = [
|
27
|
+
gem.require_paths = ['lib']
|
21
28
|
|
22
|
-
gem.
|
29
|
+
gem.metadata = {
|
30
|
+
'source_code_uri' => 'https://github.com/avamia/kanrisuru/'
|
31
|
+
}
|
23
32
|
end
|
data/lib/kanrisuru.rb
CHANGED
@@ -1,6 +1,45 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright (c) 2020-2021 Avamia, LLC
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
|
26
|
+
require_relative 'kanrisuru/version'
|
27
|
+
require_relative 'kanrisuru/logger'
|
28
|
+
require_relative 'kanrisuru/util'
|
29
|
+
require_relative 'kanrisuru/mode'
|
30
|
+
require_relative 'kanrisuru/os_package'
|
31
|
+
require_relative 'kanrisuru/command'
|
32
|
+
require_relative 'kanrisuru/remote'
|
33
|
+
require_relative 'kanrisuru/result'
|
34
|
+
require_relative 'kanrisuru/core'
|
35
|
+
require_relative 'kanrisuru/template'
|
2
36
|
|
3
37
|
module Kanrisuru
|
38
|
+
def self.logger
|
39
|
+
@logger ||= Kanrisuru::Logger.new($stdout, formatter: proc { |severity, _datetime, _progname, msg|
|
40
|
+
"#{severity}: #{msg}\n"
|
41
|
+
})
|
42
|
+
end
|
43
|
+
|
4
44
|
class Error < StandardError; end
|
5
|
-
# Your code goes here...
|
6
45
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
class Command
|
5
|
+
attr_reader :exit_status, :raw_result, :program
|
6
|
+
attr_writer :remote_user, :remote_shell, :remote_path, :remote_env
|
7
|
+
|
8
|
+
def initialize(command)
|
9
|
+
@raw_command = command
|
10
|
+
@raw_result = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def success?
|
14
|
+
@exit_status&.zero?
|
15
|
+
end
|
16
|
+
|
17
|
+
def failure?
|
18
|
+
!success?
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_i
|
22
|
+
to_a.join.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
to_a.join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_json(*_args)
|
30
|
+
JSON.parse(to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_a
|
34
|
+
string = @raw_result.join
|
35
|
+
string.lines.map(&:strip)
|
36
|
+
end
|
37
|
+
|
38
|
+
def prepared_command
|
39
|
+
if !@remote_user.nil? && !@remote_shell.nil?
|
40
|
+
evaluate = ''
|
41
|
+
evaluate += if Kanrisuru::Util.present?(@remote_path)
|
42
|
+
"cd #{@remote_path} && #{@raw_command}"
|
43
|
+
else
|
44
|
+
@raw_command.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
env = @remote_env && !@remote_env.empty? ? "#{@remote_env} " : ''
|
48
|
+
|
49
|
+
"#{env}sudo -u #{@remote_user} #{@remote_shell} -c -l \"#{evaluate}\""
|
50
|
+
else
|
51
|
+
@raw_command
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def raw_command
|
56
|
+
@raw_command.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def handle_status(status)
|
60
|
+
@exit_status = status
|
61
|
+
end
|
62
|
+
|
63
|
+
def handle_data(data)
|
64
|
+
@raw_result.push(data)
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle_signal(signal)
|
68
|
+
@signal = signal
|
69
|
+
end
|
70
|
+
|
71
|
+
def +(other)
|
72
|
+
append_value(other)
|
73
|
+
end
|
74
|
+
|
75
|
+
def <<(value)
|
76
|
+
append_value(value)
|
77
|
+
end
|
78
|
+
|
79
|
+
def |(other)
|
80
|
+
pipe(other)
|
81
|
+
end
|
82
|
+
|
83
|
+
def pipe(value)
|
84
|
+
append_value("| #{value}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def append_value(value)
|
88
|
+
@raw_command = "#{@raw_command} #{value}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def append_arg(arg, string)
|
92
|
+
@raw_command = Kanrisuru::Util.present?(string) ? "#{@raw_command} #{arg} #{string}" : @raw_command
|
93
|
+
end
|
94
|
+
|
95
|
+
def append_flag(arg, boolean = 'true')
|
96
|
+
@raw_command = Kanrisuru::Util.present?(boolean) ? "#{@raw_command} #{arg}" : @raw_command
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|