Module: D3::Admin::Prefs
- Defined in:
- lib/d3/admin/prefs.rb
Constant Summary collapse
- PREFS_DIR =
Module Constants #################
Pathname.new(ENV['HOME'].to_s). + 'Library/Preferences'
- PREFS_FILE =
PREFS_DIR + 'com.pixar.d3.admin.yaml'
- PREF_KEYS =
{ workspace: { description: "Path to the directory where new pkg and dmg packages are built.\n If unset, defaults to your home folder" }, editor: { description: 'Preferred shell command for editing package descriptions in --walkthru' }, apple_pkg_id_prefix: { description: "The Apple package id prefix, e.g. 'com.mycompany'.\nWhen .pkgs are built, the identifier will be this, plus the basename.\n If unset, the default is '#{D3::Admin::DFT_PKG_ID_PREFIX}'" }, last_config: { description: 'Timestamp of the last configuration for setting servers, credentials and/or prefs' }, signing_identity: { description: "Developer ID Installer certificate issued by the Apple Developer ID Certification Authority.\n This identity (certificate and private key) should be stored in the login.keychain of the user operating d3admin unless otherwise specified in signing options. Signing is optional." }, signing_options: { description: 'If a signing identity is defined, this String of options will be passed to pkgbuild. See man pkgbuild for more information' } }.freeze
- @@prefs =
PREFS_FILE.readable? ? YAML.load(PREFS_FILE.read) : {}
Class Method Summary collapse
-
.config(targets, options) ⇒ void
Run the Admin config, saving hostnames, usernames and pws as needed.
-
.display_config ⇒ void
Display the current Admin config settings.
-
.prefs ⇒ Hash
Return a hash of prefs for this admin.
-
.save_prefs ⇒ void
Save the current prefs to disk for this user.
-
.set_pref(pref, value) ⇒ Boolean
Set a pref and save the change.
Class Method Details
.config(targets, options) ⇒ void
TODO:
improve this a lot
This method returns an undefined value.
Run the Admin config, saving hostnames, usernames and pws as needed.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/d3/admin/prefs.rb', line 108 def self.config(targets, ) if .walkthru tgt = D3::Admin::Interactive.get_value :get_config_target, 'all' targets = [tgt] end if targets.empty? or targets.include?('all') targets = D3::Admin::CONFIG_TARGETS - ['all'] end targets.each do |target| case target when 'jss' puts '******** JSS-API LOCATION AND READ-WRITE CREDENTIALS ********' D3::Admin::Auth.ask_for_rw_credentials :jss when 'db' puts '******** JSS MYSQL LOCATION AND READ-WRITE CREDENTIALS ********' D3::Admin::Auth.ask_for_rw_credentials :db when 'dist' puts '******** MASTER DIST-POINT READ-WRITE PASSWORD ********' D3::Admin::Auth.ask_for_rw_credentials :dist when 'workspace' puts '******** LOCAL PKG/DMG BUILD WORKSPACE ********' pth = D3::Admin::Interactive.get_value :workspace, D3::Admin::Prefs.prefs[:workspace] D3::Admin::Prefs.set_pref :workspace, pth D3::Admin::Prefs.save_prefs puts 'Thank you, the path has been saved in your d3admin prefs' puts when 'editor' puts '******** TEXT EDITOR ********' cmd = D3::Admin::Interactive.get_value :get_editor, D3::Admin::Prefs.prefs[:editor] D3::Admin::Prefs.set_pref :editor, cmd D3::Admin::Prefs.save_prefs puts 'Thank you, the command has been saved in your d3admin prefs' puts when 'pkg-id-prefix' puts '******** .PKG IDENTIFIER PREFIX ********' pfx = D3::Admin::Interactive.get_value(:get_pkg_identifier_prefix, D3::Admin::Prefs.prefs[:apple_pkg_id_prefix], :validate_package_identifier_prefix) D3::Admin::Prefs.set_pref :apple_pkg_id_prefix, pfx D3::Admin::Prefs.save_prefs puts 'Thank you, the prefix has been saved in your d3admin prefs' puts when 'signing_identity' puts '******** PACKAGE SIGNING IDENTITY ********' sid = D3::Admin::Interactive.get_value :get_signing_identity, D3::Admin::Prefs.prefs[:signing_identity] D3::Admin::Prefs.set_pref :signing_identity, sid D3::Admin::Prefs.save_prefs puts 'Thank you, the signing identity has been saved in your d3admin prefs' puts when 'signing_options' puts '******** PACKAGE SIGNING OPTIONS ********' sopts = D3::Admin::Interactive.get_value :get_signing_options, D3::Admin::Prefs.prefs[:signing_options] D3::Admin::Prefs.set_pref :signing_options, sopts D3::Admin::Prefs.save_prefs puts 'Thank you, signing options have been saved in your d3admin prefs' puts else puts "(skipping unknown config setting: #{target}" end # case end # targets.each end |
.display_config ⇒ void
This method returns an undefined value.
Display the current Admin config settings
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/d3/admin/prefs.rb', line 182 def self.display_config jss_creds = D3::Admin::Auth.rw_credentials :jss, :just_checking jss_server = JSS::CONFIG.api_server_name # should be the one saved in the user-level .ruby-jss.conf, not top level in /etc jss_port = JSS::CONFIG.api_server_port db_creds = D3::Admin::Auth.rw_credentials :db, :just_checking db_server = JSS::CONFIG.db_server_name db_port = JSS::CONFIG.db_server_port dist_creds = D3::Admin::Auth.rw_credentials :dist, :just_checking wkspc = D3::Admin::Prefs.prefs[:workspace] pkg_id_pfx = D3::Admin::Prefs.prefs[:apple_pkg_id_prefix] editor = D3::Admin::Prefs.prefs[:editor] signing_id = D3::Admin::Prefs.prefs[:signing_identity] signing_opts = D3::Admin::Prefs.prefs[:signing_options] puts <<-DISPLAY ******** Current d3admin config ******** JSS API Hostname: #{jss_server} Port: #{jss_port} Read/Write user: #{jss_creds[:user] ? jss_creds[:user] : 'unset'} Read/Write password: #{jss_creds[:password] ? 'stored in keychain' : 'unset'} JSS MySQL Hostname: #{db_server} Port: #{db_port} Read/Write user: #{db_creds[:user] ? db_creds[:user] : 'unset'} Read/Write password: #{db_creds[:password] ? 'stored in keychain' : 'unset'} Master Distribution Point Hostname: (stored in JSS) Port: (stored in JSS) Read/Write user: (stored in JSS) Read/Write password: #{dist_creds[:password] ? 'stored in keychain' : 'unset'} Adding Packages Description Editor: #{editor ? editor : D3::Admin::Interactive::DFT_EDITOR} Build Workspace: #{wkspc ? wkspc : D3::Admin::DFT_WORKSPACE} Identifier Prefix: #{pkg_id_pfx ? pkg_id_pfx : D3::Admin::DFT_PKG_ID_PREFIX} Package Signing (Optional) Signing Identity: #{signing_id ? signing_id : 'N/A'} Signing Options: #{signing_opts ? signing_opts : 'N/A'} DISPLAY end |
.prefs ⇒ Hash
Return a hash of prefs for this admin
71 72 73 |
# File 'lib/d3/admin/prefs.rb', line 71 def self.prefs @@prefs end |
.save_prefs ⇒ void
This method returns an undefined value.
Save the current prefs to disk for this user
91 92 93 94 |
# File 'lib/d3/admin/prefs.rb', line 91 def self.save_prefs @@prefs[:last_config] = Time.now PREFS_FILE.jss_save YAML.dump(@@prefs) end |
.set_pref(pref, value) ⇒ Boolean
Set a pref and save the change
82 83 84 85 86 |
# File 'lib/d3/admin/prefs.rb', line 82 def self.set_pref(pref, value) raise JSS::InvalidDataError, 'first argument must be a pref key from D3::Admin::Prefs::PREF_KEYS' unless PREF_KEYS.keys.include? pref @@prefs[pref] = value save_prefs end |