terminalwire 0.1.13 → 0.1.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b3e02592c8154c835d32f4dc149d47212665f5dd2974d2634746207ced582b3
4
- data.tar.gz: 0a4b15090653b5b54a10a215db6a39ee5465cac9a10c4e1cd29ba7fc0622822a
3
+ metadata.gz: 7368802178d36d058c4502624e50e831358e6b4bc47bbb40a18a8837063443a7
4
+ data.tar.gz: eaeedd98707062d3a639250cb53e3dd619bcd3d63b1e2a6ee51d916edb5da9df
5
5
  SHA512:
6
- metadata.gz: d74b1186e46a73eb62de35f0624f20a4f3f90aa8bf24137b772423a87a09bea920886824d7175c5b08bd18c963b3823c4cccbff0e7abd44120bfe186edda84e6
7
- data.tar.gz: 9997f63145801d3ca47476ead70f49ac001f77765cb777063b44b62d96e1b3dfdf266f42897fae01eb0a9a224e8fddeb5e878533e773f11aaafe2e81512a48f4
6
+ metadata.gz: e0fb8c62c74528e3de4701ebced6e3e794d973ca67eddfdc140a645e9ecc676ae994095a3d08b4da731f3c87bf258018818d55562325016b4f4eee6dd9f17a6f
7
+ data.tar.gz: d27e62fdcf8582293fb89395acd0e9e9282c616fbb8eb9b8592f95b1a931465011ab9d006b11afa23d1719e1c97e0a61b9ffcb74619aec03f3f1a2286b57e2b6
@@ -0,0 +1,49 @@
1
+ require "uri"
2
+ require "base64"
3
+
4
+ # Resolves domains into authorities, which are is used for access
5
+ # identity control in Terminalwire.
6
+ class Terminalwire::Authority
7
+ # Used to seperate path keys in the URL.
8
+ PATH_SEPERATOR = "/".freeze
9
+
10
+ # Used to demark a URL string as authorative.
11
+ SCHEME = "terminalwire://".freeze
12
+
13
+ def initialize(url:)
14
+ @url = URI(url)
15
+ end
16
+
17
+ # Extracted from HTTP. This is so we can
18
+ def domain
19
+ if @url.port == @url.default_port
20
+ @url.host
21
+ else
22
+ "#{@url.host}:#{@url.port}"
23
+ end
24
+ end
25
+
26
+ # Useful for identifying the authority in UI without the protocol.
27
+ def name
28
+ [domain, path].join
29
+ end
30
+
31
+ # Make sure there's always a / at the end of the path.
32
+ def path
33
+ path_keys.join(PATH_SEPERATOR).prepend(PATH_SEPERATOR)
34
+ end
35
+
36
+ def to_s
37
+ [SCHEME, domain, path].join
38
+ end
39
+
40
+ def key
41
+ Base64.urlsafe_encode64(to_s)
42
+ end
43
+
44
+ protected
45
+
46
+ def path_keys
47
+ @url.path.scan(/[^\/]+/)
48
+ end
49
+ end
@@ -145,7 +145,8 @@ module Terminalwire::Client
145
145
  end
146
146
 
147
147
  def authority_path
148
- root_path.join("authorities/#{authority}")
148
+ # TODO: Change this so it's per endpoint and not domain
149
+ root_path.join("authorities/#{authority.domain}")
149
150
  end
150
151
 
151
152
  def storage_path
@@ -158,7 +159,7 @@ module Terminalwire::Client
158
159
 
159
160
  def serialize
160
161
  {
161
- authority: @authority,
162
+ authority: @authority.to_s,
162
163
  schemes: @schemes.serialize,
163
164
  paths: @paths.serialize,
164
165
  storage_path: storage_path.to_s,
@@ -203,23 +204,13 @@ module Terminalwire::Client
203
204
  end
204
205
 
205
206
  def self.from_url(url)
206
- url = URI(url)
207
+ authority = Terminalwire::Authority.new(url:)
207
208
 
208
- case url.host
209
+ case authority.domain
209
210
  when RootPolicy::HOST
210
- RootPolicy.new
211
+ RootPolicy.new authority:
211
212
  else
212
- Policy.new authority: url_authority(url)
213
- end
214
- end
215
-
216
- def self.url_authority(url)
217
- # I had to lift this from URI::HTTP because `ws://` doesn't
218
- # have an authority method.
219
- if url.port == url.default_port
220
- url.host
221
- else
222
- "#{url.host}:#{url.port}"
213
+ Policy.new authority:
223
214
  end
224
215
  end
225
216
  end
@@ -53,15 +53,6 @@ module Terminalwire
53
53
  end
54
54
  end
55
55
 
56
- # Extracted from HTTP. This is so we can
57
- def self.authority(url)
58
- if url.port == url.default_port
59
- url.host
60
- else
61
- "#{url.host}:#{url.port}"
62
- end
63
- end
64
-
65
56
  def self.websocket(url:, arguments: ARGV, entitlement: nil)
66
57
  url = URI(url)
67
58
 
@@ -14,6 +14,10 @@ module Terminalwire::Licensing
14
14
  generate_private_key.to_pem
15
15
  end
16
16
 
17
+ def self.time
18
+ Time.now.utc
19
+ end
20
+
17
21
  # Handles encoding data into a license key with prefixes that can be packed and unpacked.
18
22
  module Key
19
23
  # Mix into classes that need to generate or read keys
@@ -84,10 +88,10 @@ module Terminalwire::Licensing
84
88
 
85
89
  VERSION = "1.0".freeze
86
90
 
87
- def initialize(public_key:, license_url:)
91
+ def initialize(public_key:, license_url:, generated_at: Terminalwire::Licensing.time)
88
92
  @public_key = public_key
89
93
  @license_url = URI(license_url)
90
- @generated_at = Time.now.utc
94
+ @generated_at = generated_at
91
95
  end
92
96
 
93
97
  def to_h
@@ -111,7 +115,7 @@ module Terminalwire::Licensing
111
115
 
112
116
  # This means the server will tolerate a 10 minute drift in the generated_at time.
113
117
  def self.drift
114
- now = Time.now.utc
118
+ now = Terminalwire::Licensing.time
115
119
  (now - DRIFT_SECONDS)...(now + DRIFT_SECONDS)
116
120
  end
117
121
 
@@ -147,10 +151,10 @@ module Terminalwire::Licensing
147
151
  include Key::Serialization
148
152
  PREFIX = "client_key_".freeze
149
153
 
150
- def initialize(server_key:)
154
+ def initialize(server_key:, generated_at: Terminalwire::Licensing.time)
151
155
  @data = Issuer::ServerKeyGenerator.deserialize server_key
152
- @generated_at = Time.now.utc
153
156
  @license_url = URI(@data.fetch("license_url"))
157
+ @generated_at = generated_at
154
158
  end
155
159
 
156
160
  def to_h
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terminalwire
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.15"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminalwire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-26 00:00:00.000000000 Z
11
+ date: 2024-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-websocket
@@ -161,6 +161,7 @@ files:
161
161
  - lib/generators/terminalwire/install/templates/main_terminal.rb
162
162
  - lib/terminalwire.rb
163
163
  - lib/terminalwire/adapter.rb
164
+ - lib/terminalwire/authority.rb
164
165
  - lib/terminalwire/client.rb
165
166
  - lib/terminalwire/client/entitlement.rb
166
167
  - lib/terminalwire/client/exec.rb