lib/d3/admin/auth.rb in depot3-3.0.9 vs lib/d3/admin/auth.rb in depot3-3.0.11
- old
+ new
@@ -48,10 +48,13 @@
KEYCHAIN_DIST_ACCT = "defined_in_jss"
KEYCHAIN_DIST_SERVICE = KEYCHAIN_SERVICE_BASE + ".distribution"
KEYCHAIN_DIST_LABEL = KEYCHAIN_LABEL_BASE + ".distribution"
+ @@connected = false
+
+
### Connect to the JSS API and MySQL DB
### with admin credentials from the keychain
###
### @return [String] the JSS hostname to which the connection was made
###
@@ -60,19 +63,35 @@
db = rw_credentials :db
JSS::DB_CNX.connect :user => db[:user], :pw => db[:password], :connect_timeout => 10
JSS::API.connect :user => api[:user], :pw => api[:password], :open_timeout => 10
D3::Database.check_schema_version
+
+ @@connected = true
+
return JSS::API.cnx.options[:server]
end
- # Disconnect admin credentials from the JSS API and MySQL DB
+ ### Disconnect admin credentials from the JSS API and MySQL DB
+ ###
+ ### @return [void]
+ ###
def disconnect
JSS::API.disconnect if JSS::API.connected?
JSS::DB_CNX.disconnect if JSS::DB_CNX.connected?
+ @@connected = false
end
+ ### Are we currently connected as an admin?
+ ###
+ ### return [Boolean]
+ ###
+ def connected?
+ @@connected
+ end
+
+
### Fetch read-write credentials from the login keychain
###
### If the login keychain is locked, the user will be prompted
### to unlock it in the GUI.
###
@@ -447,11 +466,9 @@
end #begin..ensure
raise JSS::AuthenticationError, "Three incorrect attempts to unlock keychain" if tries == 3
return true
end # unlock keychain
-
-
end # module Auth
### @see D3::Admin::Auth.connect
###
def self.connect (alt_db = false)