terminalwire-core 0.3.0.alpha3 → 0.3.0.alpha5

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: 4ae7aa6a122b7ac22de1ebca937863d810e0c457dbfd32c745b476b9a0aaf7ed
4
- data.tar.gz: 70cf906a0ce92114735041a947d93c899f6935cd040db1d75e8b996052abe21c
3
+ metadata.gz: 5d61009ab0d549eccb717f1e50f358c9eeb4a46fe59228eabcd99df9f046bb17
4
+ data.tar.gz: 9962069681ed21463e882e0586ee3e0bb21284d42df18cc478bd934cf2c56f1d
5
5
  SHA512:
6
- metadata.gz: 4284e78811e1a01e3074539c6041aea2403d690d0f371d95defcd0e2ed4f011a6b33311378b80f8766f327ab26ec05304329578cf5a3861786e0dfe68a0d965a
7
- data.tar.gz: 9516e5f515ca0da309a18a286764d15f31de379a76eea2c42c365bfd02f54e8b5defa264b583570c0b1a6047ba7d8dfc361bda2d9d3c7a00752be84ea99344ba
6
+ metadata.gz: 19c0427569937fc06083573dc559d6a53ef1d703339876fd88a7f3dc14cc069adf4e89107fe94d440852bfa5694bec7b671f1c83baee21746efa63d9672e7ed4
7
+ data.tar.gz: 6550d9093fdc9729e502c874b1b6e73d88d18b48a850ce1d4f737f2622db746fd3ec5408e47f4c065d044da4c3e4f6ba79d044634c29d2302c9d146b70dd8069
@@ -0,0 +1,52 @@
1
+ require "uri"
2
+ require "yaml"
3
+
4
+ module Terminalwire
5
+ # Generates Terminalwire binary file stubs. These files then run using
6
+ # the `terminalwire-exec` command.
7
+ class Binary
8
+ SHEBANG = "#!/usr/bin/env terminalwire-exec".freeze
9
+
10
+ ASSIGNABLE_KEYS = %w[url]
11
+
12
+ attr_reader :url
13
+
14
+ def initialize(url: nil)
15
+ self.url = url if url
16
+ end
17
+
18
+ def url=(value)
19
+ @url = URI(value)
20
+ end
21
+
22
+ def body
23
+ <<~BASH
24
+ #{SHEBANG}
25
+ url: "#{url.to_s}"
26
+ BASH
27
+ end
28
+
29
+ def assign(**hash)
30
+ ASSIGNABLE_KEYS.each do |key|
31
+ public_send "#{key}=", hash[key] if hash.key? key
32
+ end
33
+ self
34
+ end
35
+
36
+ # Writes the binary to the given path.
37
+ def write(path)
38
+ File.open(path, "w") do |file|
39
+ file.write body
40
+ file.chmod 0755
41
+ end
42
+ end
43
+
44
+ def self.open(path)
45
+ new.assign **YAML.safe_load_file(path)
46
+ end
47
+
48
+ def self.write(url:, to:)
49
+ new(url: url).write to
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,141 @@
1
+ module Terminalwire
2
+ module Shells
3
+ # This is used to detect what the user is running for a shell. Terminalwire then
4
+ # then uses this information to determine what files to write to for the root policy.
5
+ #
6
+ class Shell
7
+ attr_reader :name, :login_files, :interactive_files, :logout_files
8
+
9
+ def initialize(name)
10
+ @name = name
11
+ @login_files = Set.new
12
+ @interactive_files = Set.new
13
+ @logout_files = Set.new
14
+ end
15
+
16
+ class Configuration
17
+ attr_reader :shell
18
+
19
+ def initialize(shell, &block)
20
+ @shell = shell
21
+ instance_eval(&block) if block_given?
22
+ end
23
+
24
+ def login_file(*paths)
25
+ shell.login_files.merge paths.flatten
26
+ end
27
+ alias :login_files :login_file
28
+
29
+ def interactive_file(*paths)
30
+ shell.interactive_files.merge paths.flatten
31
+ end
32
+ alias :interactive_files :interactive_file
33
+
34
+ def logout_file(*paths)
35
+ shell.logout_files.merge paths.flatten
36
+ end
37
+ alias :logout_files :logout_file
38
+ end
39
+
40
+ def configure(&block)
41
+ Configuration.new(self, &block).shell
42
+ end
43
+ end
44
+
45
+ # Encapsulates a collection of shells.
46
+ class Collection
47
+ attr_reader :shells
48
+ include Enumerable
49
+
50
+ def initialize
51
+ @shells = []
52
+ end
53
+
54
+ def shell(name, &)
55
+ shells << Shell.new(name).configure(&)
56
+ end
57
+
58
+ def each(&)
59
+ shells.each(&)
60
+ end
61
+
62
+ def login_files
63
+ shells.flat_map { |shell| shell.login_files.to_a }.reject(&:empty?)
64
+ end
65
+
66
+ def interactive_files
67
+ shells.flat_map { |shell| shell.interactive_files.to_a }.reject(&:empty?)
68
+ end
69
+
70
+ def logout_files
71
+ shells.flat_map { |shell| shell.logout_files.to_a }.reject(&:empty?)
72
+ end
73
+
74
+ def names
75
+ shells.map(&:name)
76
+ end
77
+
78
+ def find_by_shell(name)
79
+ shells.find { |shell| shell.name == name }
80
+ end
81
+
82
+ def find_by_shell_path(path)
83
+ return if path.nil?
84
+ find_by_shell(File.basename(path))
85
+ end
86
+
87
+ def files
88
+ login_files + interactive_files + logout_files
89
+ end
90
+
91
+ def self.configure(&block)
92
+ Collection.new.tap do |collection|
93
+ collection.instance_eval(&block) if block_given?
94
+ end
95
+ end
96
+ end
97
+
98
+ All = Collection.configure do
99
+ shell "bash" do
100
+ login_files %w[~/.bash_profile ~/.bash_login ~/.profile]
101
+ interactive_file "~/.bashrc"
102
+ logout_file "~/.bash_logout"
103
+ end
104
+
105
+ shell "zsh" do
106
+ login_files %w[~/.zprofile ~/.zshenv]
107
+ interactive_file "~/.zshrc"
108
+ logout_file "~/.zlogout"
109
+ end
110
+
111
+ shell "sh" do
112
+ login_files %w[~/.profile]
113
+ end
114
+
115
+ shell "dash" do
116
+ login_files %w[~/.profile]
117
+ end
118
+
119
+ shell "fish" do
120
+ interactive_file "~/.config/fish/config.fish"
121
+ end
122
+
123
+ shell "ksh" do
124
+ login_files %w[~/.profile]
125
+ interactive_file "~/.kshrc"
126
+ end
127
+
128
+ shell "csh" do
129
+ login_files %w[~/.cshrc ~/.login]
130
+ interactive_file "~/.cshrc"
131
+ logout_file "~/.logout"
132
+ end
133
+
134
+ shell "tcsh" do
135
+ login_files %w[~/.cshrc ~/.login]
136
+ interactive_file "~/.cshrc"
137
+ logout_file "~/.logout"
138
+ end
139
+ end
140
+ end
141
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terminalwire
4
- VERSION = "0.3.0.alpha3"
4
+ VERSION = "0.3.0.alpha5"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminalwire-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.alpha3
4
+ version: 0.3.0.alpha5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-17 00:00:00.000000000 Z
10
+ date: 2025-02-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: async-websocket
@@ -117,8 +117,10 @@ files:
117
117
  - lib/terminalwire-core.rb
118
118
  - lib/terminalwire.rb
119
119
  - lib/terminalwire/adapter.rb
120
+ - lib/terminalwire/binary.rb
120
121
  - lib/terminalwire/cache.rb
121
122
  - lib/terminalwire/logging.rb
123
+ - lib/terminalwire/shells.rb
122
124
  - lib/terminalwire/transport.rb
123
125
  - lib/terminalwire/version.rb
124
126
  homepage: https://terminalwire.com/ruby