terminalwire 0.1.2 → 0.1.4

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: 8eacca5d9e410385fee49a9115cdc9d92ac1276b0666af88b8c343f11306a05f
4
- data.tar.gz: c94050aef56399743f202c13c3813bb66a05cfffd2333ea9431bccded43234f2
3
+ metadata.gz: 1961141ea3c3667bbff1f44be8f95ce247128f9c41fe7c98b0f96bb4b1c5099e
4
+ data.tar.gz: e206f7d31c8632a5e25a9d8e2d5e4eb974927450c463abb7f474887d07b7c1a1
5
5
  SHA512:
6
- metadata.gz: 2a25a33121a603fdcb11c5c664d17772f999d4a379379390ad578ed434fa75428f45deda6d2023e490ecf2bedfad61cf58a9fd4d7c880e17fff714978075159c
7
- data.tar.gz: 76e5bf2edd88ad0ca092328514ebce7bc22ee64ff13aa4ebf83c77319849fe2564515cc89bf27364f3135ca2456143869066ca6eaef70daae15dabedb006b3e3
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,16 +73,19 @@ 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|
80
- endpoint = Async::HTTP::Endpoint.parse(url)
80
+ endpoint = Async::HTTP::Endpoint.parse(
81
+ url,
82
+ alpn_protocols: Async::HTTP::Protocol::HTTP11.names
83
+ )
81
84
 
82
85
  Async::WebSocket::Client.connect(endpoint) do |adapter|
83
86
  transport = Terminalwire::Transport::WebSocket.new(adapter)
84
87
  adapter = Terminalwire::Adapter.new(transport)
85
- entitlement = Entitlement.from_url(url)
88
+ entitlement ||= Entitlement.from_url(url)
86
89
  Terminalwire::Client::Handler.new(adapter, arguments:, entitlement:).connect
87
90
  end
88
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.2"
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.2
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-16 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.