Class: Puppet::Provider::RustupExec
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::RustupExec
- Defined in:
- lib/puppet/provider/rustup_exec.rb
Overview
Base class for rustup providers
Class Method Summary collapse
-
.instances ⇒ Object
It’s not really reliable to query rustup installations by user, since they could be installed with CARGO_HOME anywhere.
-
.subresource_collection(name, klass) ⇒ Object
Add a subresource that gets managed somewhat separately.
Instance Method Summary collapse
-
#bin_path ⇒ Object
Get path to directory where cargo installs binaries.
-
#create ⇒ Object
The resource thinks we need to create it on the system.
-
#destroy ⇒ Object
The resource thinks we need to destroy it on the system.
-
#ensure_absent ⇒ Object
Ensure it’s really gone.
-
#ensure_not_absent ⇒ Object
Make sure all the bits and pieces are installed.
-
#exists? ⇒ Boolean
Determine if the resource exists on the system.
-
#flush ⇒ Object
Changes have been made to the resource; apply them.
-
#initialize ⇒ RustupExec
constructor
A new instance of RustupExec.
-
#path_env ⇒ Object
Get PATH, including cargo_home/bin.
-
#rustup(*args) ⇒ Object
Run rustup as the user.
-
#rustup_installed? ⇒ Boolean
Determine if ‘rustup` has been installed on the system for this user.
-
#rustup_path ⇒ Object
Get path to rustup binary.
-
#update ⇒ Object
The resource thinks we need to update it on the system.
-
#user_entry ⇒ Object
Get the entry in /etc/passwd for the specified user.
-
#user_exists? ⇒ Boolean
Check if the specified user actually exists.
Constructor Details
#initialize ⇒ RustupExec
Returns a new instance of RustupExec.
26 27 28 29 |
# File 'lib/puppet/provider/rustup_exec.rb', line 26 def initialize(*) super @subresource_collections = {} end |
Class Method Details
.instances ⇒ Object
It’s not really reliable to query rustup installations by user, since they could be installed with CARGO_HOME anywhere.
7 8 9 |
# File 'lib/puppet/provider/rustup_exec.rb', line 7 def self.instances raise Puppet::Error, 'Cannot query rustup installations.' end |
.subresource_collection(name, klass) ⇒ Object
Add a subresource that gets managed somewhat separately
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puppet/provider/rustup_exec.rb', line 12 def self.subresource_collection(name, klass) name = name.to_sym # Get current subresources define_method(name) do @subresource_collections[name] ||= klass.new(self) end # Set current subresources define_method("#{name}=") do |values| @subresource_collections[name].values = values end end |
Instance Method Details
#bin_path ⇒ Object
Get path to directory where cargo installs binaries
104 105 106 |
# File 'lib/puppet/provider/rustup_exec.rb', line 104 def bin_path File.join(resource[:cargo_home], 'bin') end |
#create ⇒ Object
The resource thinks we need to create it on the system.
This is called from the ‘ensurable` block on the resource, e.g:
newvalue(:present) { provider.create }
40 41 42 |
# File 'lib/puppet/provider/rustup_exec.rb', line 40 def create raise 'Unimplemented.' end |
#destroy ⇒ Object
The resource thinks we need to destroy it on the system.
This is called from the ‘ensurable` block on the resource, e.g:
newvalue(:absent) { provider.destroy }
56 57 58 |
# File 'lib/puppet/provider/rustup_exec.rb', line 56 def destroy raise 'Unimplemented.' end |
#ensure_absent ⇒ Object
Ensure it’s really gone.
This is called if ‘ensure` is `absent` even if `exists? == false`.
75 |
# File 'lib/puppet/provider/rustup_exec.rb', line 75 def ensure_absent; end |
#ensure_not_absent ⇒ Object
Make sure all the bits and pieces are installed.
This is called when ‘ensure` is not `absent`, i.e. `present` or `latest`. It is called even if `exist? == true`.
81 |
# File 'lib/puppet/provider/rustup_exec.rb', line 81 def ensure_not_absent; end |
#exists? ⇒ Boolean
Determine if the resource exists on the system.
32 33 34 |
# File 'lib/puppet/provider/rustup_exec.rb', line 32 def exists? raise 'Unimplemented.' end |
#flush ⇒ Object
Changes have been made to the resource; apply them.
Installing, updating, and uninstalling rustup is handled separately because of the way Puppet logs things.
64 65 66 67 68 69 70 |
# File 'lib/puppet/provider/rustup_exec.rb', line 64 def flush if resource[:ensure] == :absent ensure_absent else ensure_not_absent end end |
#path_env ⇒ Object
Get PATH, including cargo_home/bin
99 100 101 |
# File 'lib/puppet/provider/rustup_exec.rb', line 99 def path_env "#{bin_path}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" end |
#rustup(*args) ⇒ Object
Run rustup as the user
89 90 91 |
# File 'lib/puppet/provider/rustup_exec.rb', line 89 def rustup(*args) execute([rustup_path] + args) end |
#rustup_installed? ⇒ Boolean
Determine if ‘rustup` has been installed on the system for this user
84 85 86 |
# File 'lib/puppet/provider/rustup_exec.rb', line 84 def rustup_installed? File.file? rustup_path end |
#rustup_path ⇒ Object
Get path to rustup binary
94 95 96 |
# File 'lib/puppet/provider/rustup_exec.rb', line 94 def rustup_path File.join(bin_path, 'rustup') end |
#update ⇒ Object
The resource thinks we need to update it on the system.
This is called from the ‘ensurable` block on the resource, e.g:
newvalue(:latest) { provider.update }
48 49 50 |
# File 'lib/puppet/provider/rustup_exec.rb', line 48 def update raise 'Unimplemented.' end |
#user_entry ⇒ Object
Get the entry in /etc/passwd for the specified user.
109 110 111 112 113 |
# File 'lib/puppet/provider/rustup_exec.rb', line 109 def user_entry Etc.getpwnam(resource[:user]) rescue ArgumentError nil end |
#user_exists? ⇒ Boolean
Check if the specified user actually exists.
116 117 118 |
# File 'lib/puppet/provider/rustup_exec.rb', line 116 def user_exists? !user_entry.nil? end |