Class: Puppet::Provider::RustupExec

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/rustup_exec.rb

Overview

Base class for rustup providers

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRustupExec

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

.instancesObject

It’s not really reliable to query rustup installations by user, since they could be installed with CARGO_HOME anywhere.

Raises:

  • (Puppet::Error)


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_pathObject

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

#createObject

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

#destroyObject

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_absentObject

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_absentObject

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.

Returns:

  • (Boolean)


32
33
34
# File 'lib/puppet/provider/rustup_exec.rb', line 32

def exists?
  raise 'Unimplemented.'
end

#flushObject

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_envObject

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

Returns:

  • (Boolean)


84
85
86
# File 'lib/puppet/provider/rustup_exec.rb', line 84

def rustup_installed?
  File.file? rustup_path
end

#rustup_pathObject

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

#updateObject

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_entryObject

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.

Returns:

  • (Boolean)


116
117
118
# File 'lib/puppet/provider/rustup_exec.rb', line 116

def user_exists?
  !user_entry.nil?
end