sprites-ruby 0.2.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/CHANGELOG.md +4 -0
- data/README.md +173 -2
- data/lib/sprites/client.rb +5 -1
- data/lib/sprites/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5da75311f037ca5acfc55a350835e258e792f06221d4f9fab135e7ba567676b0
|
|
4
|
+
data.tar.gz: c8ef0d1914539b8e618dea6aad2bf9641269d5396397950d1048a9295fc399f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd6283f8bee73c8a9adcb7a039cef763d2109e980da95fd4ec9eccd852af89a89b4b894b5299c2d76afa87edb2bbb61edbe3c4bab5d17dab8169c0d9b037d523
|
|
7
|
+
data.tar.gz: 9e96fe5d15b8f974fce96a1ced6740aa83ba6a77f78abb7e2a682668b29c03b49c4cd7b4f5f7938c1c3073b1e84e5be9b37ce44864be736d1442f3bf9a887e14
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,13 +1,184 @@
|
|
|
1
|
-
# Sprites
|
|
1
|
+
# Sprites
|
|
2
2
|
|
|
3
|
-
Ruby client for the [Sprites](https://sprites.dev) API.
|
|
3
|
+
Ruby client for the [Sprites](https://sprites.dev) API - stateful sandbox environments.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
7
9
|
```ruby
|
|
8
10
|
gem "sprites-ruby"
|
|
9
11
|
```
|
|
10
12
|
|
|
13
|
+
## Getting Started
|
|
14
|
+
|
|
15
|
+
Create a client
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
client = Sprites::Client.new(token: ENV["SPRITES_TOKEN"])
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or configure globally
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
Sprites.configure do |config|
|
|
25
|
+
config.token = ENV["SPRITES_TOKEN"]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
client = Sprites::Client.new
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Sprites
|
|
32
|
+
|
|
33
|
+
Create a sprite
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
sprite = client.sprites.create(name: "my-sprite")
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Create and wait until ready
|
|
40
|
+
|
|
41
|
+
```ruby
|
|
42
|
+
sprite = client.sprites.create(name: "my-sprite", wait: true)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
List sprites
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
collection = client.sprites.list
|
|
49
|
+
collection.sprites.each { |s| puts s.name }
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Get a sprite
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
sprite = client.sprites.retrieve("my-sprite")
|
|
56
|
+
sprite.status # => "warm"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Update a sprite
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
sprite = client.sprites.update("my-sprite", url_settings: { auth: "public" })
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Delete a sprite
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
client.sprites.delete("my-sprite")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Command Execution
|
|
72
|
+
|
|
73
|
+
Run a command (HTTP, simple)
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
result = client.exec.create("my-sprite", command: "echo hello")
|
|
77
|
+
result[:output] # => "hello\n"
|
|
78
|
+
result[:exit_code] # => 0
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Run a command (WebSocket, streaming)
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
result = client.exec.run("my-sprite", ["ls", "-la"])
|
|
85
|
+
result.stdout
|
|
86
|
+
result.stderr
|
|
87
|
+
result.exit_code
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Interactive terminal session
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
client.exec.interactive("my-sprite", ["bash"])
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
With custom I/O
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
client.exec.interactive("my-sprite", ["bash"], input: $stdin, output: $stdout)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Sessions
|
|
103
|
+
|
|
104
|
+
List active sessions
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
sessions = client.exec.list("my-sprite")
|
|
108
|
+
sessions.each { |s| puts "#{s[:id]}: #{s[:command]}" }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Attach to a session
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
114
|
+
client.exec.attach("my-sprite", session_id)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Kill a session
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
client.exec.kill("my-sprite", session_id)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
With a specific signal
|
|
124
|
+
|
|
125
|
+
```ruby
|
|
126
|
+
client.exec.kill("my-sprite", session_id, signal: "SIGKILL")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Checkpoints
|
|
130
|
+
|
|
131
|
+
Create a checkpoint
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
client.checkpoints.create("my-sprite", comment: "before deploy")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
List checkpoints
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
checkpoints = client.checkpoints.list("my-sprite")
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Restore a checkpoint
|
|
144
|
+
|
|
145
|
+
```ruby
|
|
146
|
+
client.checkpoints.restore("my-sprite", checkpoint_id)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Network Policies
|
|
150
|
+
|
|
151
|
+
Get current policy
|
|
152
|
+
|
|
153
|
+
```ruby
|
|
154
|
+
policy = client.policies.retrieve("my-sprite")
|
|
155
|
+
policy[:egress][:policy] # => "allow-all"
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Update policy
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
client.policies.update("my-sprite", egress: { policy: "block-all" })
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Low-Level WebSocket API
|
|
165
|
+
|
|
166
|
+
For advanced use cases, use `connect` directly
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
client.exec.connect("my-sprite", command: ["bash"], tty: true) do |task, session|
|
|
170
|
+
session.on_stdout { |data| print data }
|
|
171
|
+
session.on_stderr { |data| $stderr.print data }
|
|
172
|
+
session.on_exit { |code| puts "Exit: #{code}" }
|
|
173
|
+
|
|
174
|
+
task.async do
|
|
175
|
+
while (line = $stdin.gets)
|
|
176
|
+
session.write(line)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
```
|
|
181
|
+
|
|
11
182
|
## Development
|
|
12
183
|
|
|
13
184
|
```sh
|
data/lib/sprites/client.rb
CHANGED
|
@@ -104,7 +104,11 @@ module Sprites
|
|
|
104
104
|
raise Error, body.strip
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
def parse_json(json)
|
|
107
|
+
def parse_json(json)
|
|
108
|
+
return nil if json.to_s.empty?
|
|
109
|
+
|
|
110
|
+
JSON.parse(json, symbolize_names: true)
|
|
111
|
+
end
|
|
108
112
|
|
|
109
113
|
def parse_ndjson(body) = body.each_line.map { parse_json(it) }
|
|
110
114
|
|
data/lib/sprites/version.rb
CHANGED