-
Notifications
You must be signed in to change notification settings - Fork 29
2023 demo C Connecting
- open terminal window
- Run
irb
% irb
irb(main):001:0>
-
'irb' stands for 'interactive ruby', a real-time ruby interpreter
- You can type ruby code into it - just like you type bash code into a shell
-
Enter a line of ruby code, it runs and displays the 'return value' after a
=>
-
For clarity & easier copy-pasting, in this document:
- The irb examples will use no prompt
- Example output will start with a
#
, soirb
will ignore it if you play with this on your own and paste it in
- In irb, tell ruby that you want to use ruby-jss:
require 'ruby-jss'
# => true
-
Don't worry if you ever
require
returnsfalse
, it just means the thing has already been required -
Ruby is now aware of a module called
Jamf
which contains all of the ruby-jss code- Note that
JSS
is a synonym for theJamf
module, you can use them interchangably. A lot of older code uses JSS.
- Note that
-
While we're requiring, lets do this:
require 'pp'
# => true
-
'Pretty Print' allows us to examine ruby objects in irb in a more readable format.
-
In this demo, lots of ruby commands I'll paste into irb will end with
;0
- This makes the irb responses even easier to read - the return value of the line of code is just
0
- When writing scripts there's no need to do it
- This makes the irb responses even easier to read - the return value of the line of code is just
Jamf.connect 'https://[email protected]/'
# Enter the password for JSS user [email protected]:
# => "[email protected], name: default"
-
By default, you are prompted for the password, but it can be passed in to the 'connect' method also.
-
Here's what we did:
- The Jamf module has a method (function)
connect
that activates the default APIConnection object - That method takes the parameters needed to connect to the server.
- You can provide a URL or the indiviual parameters like host:, user:, pw:, port: and more.
- By default, you are prompted for the password, but it can be passed in to the 'connect' method also.
- when passing in passwords, beware of security issues
- If the password is correct, the connection is made, and the
connect
method returns the server name and the connection name. In this case we are using ruby-jss's 'default' connection, most of the time this is sufficient.
- The Jamf module has a method (function)
Connection objects in ruby-jss automatically deal with getting a bearer token and using it as required, they will also automatically renew that token under the hood (by default, tokens only last 30 minutes).