terminalwire 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ead7a2a6c5dd85df538207c79375828340610234379285c307a9a4b4d3a2234d
4
- data.tar.gz: dc187c18a311eb770d2fc0166b129fd5fd0af1849b6723ad77dd84d5c96b70b0
3
+ metadata.gz: 1961141ea3c3667bbff1f44be8f95ce247128f9c41fe7c98b0f96bb4b1c5099e
4
+ data.tar.gz: e206f7d31c8632a5e25a9d8e2d5e4eb974927450c463abb7f474887d07b7c1a1
5
5
  SHA512:
6
- metadata.gz: a076ab3977651c2607b95686b688c353753b2d9429045951d8e8593c81a3741dd6b1d11377709300f4109a36edbe8239d1dd248be3d0fa420cb73320cc50ee28
7
- data.tar.gz: fc0c370d02ef068adc839e3086733eab0878e60fa71f417605cce990083d4f66925db0170ced28292aa090ae512679189ce4af5a7613ab618a5aa2b3c539afc6
6
+ metadata.gz: 765fb306bb7c354511db2c0e6be9641c91d9207bbf2a97bcc6a0e67b039ab785061be38b0acc4ebea8a9784e43b3f211acefe9cda3200ed16dce1d14b95ce3f8
7
+ data.tar.gz: 3d2ebd1e83bdc9bd6fa742b2ebc496fc871ead16bf43a487c47d236ac18a863494542c0fcb5cbea6bf9c3f366fbffe5c374a49c054b96463d134912329c243a4
@@ -1,5 +1,5 @@
1
1
  module Terminalwire::Client
2
- class Entitlement
2
+ module Entitlement
3
3
  class Paths
4
4
  include Enumerable
5
5
 
@@ -55,53 +55,89 @@ module Terminalwire::Client
55
55
  end
56
56
  end
57
57
 
58
- attr_reader :paths, :authority, :schemes
58
+ class Policy
59
+ attr_reader :paths, :authority, :schemes
59
60
 
60
- def initialize(authority:)
61
- @authority = authority
62
- @paths = Paths.new
61
+ ROOT_PATH = "~/.terminalwire".freeze
63
62
 
64
- # Permit the domain directory. This is necessary for basic operation of the client.
65
- @paths.permit storage_path
66
- @paths.permit storage_pattern
63
+ def initialize(authority:)
64
+ @authority = authority
65
+ @paths = Paths.new
67
66
 
68
- @schemes = Schemes.new
69
- # Permit http & https by default.
70
- @schemes.permit "http"
71
- @schemes.permit "https"
72
- end
67
+ # Permit the domain directory. This is necessary for basic operation of the client.
68
+ @paths.permit storage_path
69
+ @paths.permit storage_pattern
73
70
 
74
- def domain_path
75
- Pathname.new("~/.terminalwire/authorities/#{@authority}").expand_path
76
- end
71
+ @schemes = Schemes.new
72
+ # Permit http & https by default.
73
+ @schemes.permit "http"
74
+ @schemes.permit "https"
75
+ end
77
76
 
78
- def storage_path
79
- domain_path.join("storage")
80
- end
77
+ def root_path
78
+ Pathname.new(ROOT_PATH)
79
+ end
80
+
81
+ def authority_path
82
+ root_path.join("authorities/#{authority}")
83
+ end
84
+
85
+ def storage_path
86
+ authority_path.join("storage")
87
+ end
81
88
 
82
- def storage_pattern
83
- storage_path.join("**/*")
89
+ def storage_pattern
90
+ storage_path.join("**/*")
91
+ end
92
+
93
+ def serialize
94
+ {
95
+ authority: @authority,
96
+ schemes: @schemes.serialize,
97
+ paths: @paths.serialize,
98
+ storage_path: storage_path.to_s,
99
+ }
100
+ end
84
101
  end
85
102
 
86
- def serialize
87
- {
88
- authority: @authority,
89
- schemes: @schemes.serialize,
90
- paths: @paths.serialize,
91
- storage_path: storage_path.to_s,
92
- }
103
+ class RootPolicy < Policy
104
+ HOST = "terminalwire.com".freeze
105
+
106
+ def initialize(*, **, &)
107
+ # Make damn sure the authority is set to Terminalwire.
108
+ super(*, authority: HOST, **, &)
109
+
110
+ # Now setup special permitted paths.
111
+ @paths.permit root_path
112
+ @paths.permit root_pattern
113
+ end
114
+
115
+ # Grant access to the `~/.terminalwire/**/*` path so users can install
116
+ # terminalwire apps via `terminalwire install svbtle`, etc.
117
+ def root_pattern
118
+ root_path.join("**/*")
119
+ end
93
120
  end
94
121
 
95
122
  def self.from_url(url)
123
+ url = URI(url)
124
+
125
+ case url.host
126
+ when RootPolicy::HOST
127
+ RootPolicy.new
128
+ else
129
+ Policy.new authority: url_authority(url)
130
+ end
131
+ end
132
+
133
+ def self.url_authority(url)
96
134
  # I had to lift this from URI::HTTP because `ws://` doesn't
97
135
  # have an authority method.
98
- authority = if url.port == url.default_port
136
+ if url.port == url.default_port
99
137
  url.host
100
138
  else
101
139
  "#{url.host}:#{url.port}"
102
140
  end
103
-
104
- new authority:
105
141
  end
106
142
  end
107
143
  end
@@ -73,7 +73,7 @@ module Terminalwire
73
73
  end
74
74
  end
75
75
 
76
- def self.websocket(url:, arguments: ARGV)
76
+ def self.websocket(url:, arguments: ARGV, entitlement: nil)
77
77
  url = URI(url)
78
78
 
79
79
  Async do |task|
@@ -85,7 +85,7 @@ module Terminalwire
85
85
  Async::WebSocket::Client.connect(endpoint) do |adapter|
86
86
  transport = Terminalwire::Transport::WebSocket.new(adapter)
87
87
  adapter = Terminalwire::Adapter.new(transport)
88
- entitlement = Entitlement.from_url(url)
88
+ entitlement ||= Entitlement.from_url(url)
89
89
  Terminalwire::Client::Handler.new(adapter, arguments:, entitlement:).connect
90
90
  end
91
91
  end
@@ -36,6 +36,10 @@ module Terminalwire
36
36
  :puts, :print
37
37
  def_delegators :stdin,
38
38
  :gets
39
+
40
+ # Feels more naturual to call `client.files` etc. from
41
+ # the serve since it's more apparent that it's a client.
42
+ alias :client :context
39
43
  end
40
44
  end
41
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terminalwire
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
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.3
4
+ version: 0.1.4
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-09-17 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-websocket
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  requirements: []
195
- rubygems_version: 3.5.9
195
+ rubygems_version: 3.5.3
196
196
  signing_key:
197
197
  specification_version: 4
198
198
  summary: Ship a CLI for your web app. No API required.