ruby-jss icon indicating copy to clipboard operation
ruby-jss copied to clipboard

Get ruby-jss working in Ruby v3+

Open glenfarclas17 opened this issue 3 years ago • 5 comments

There are definitely problems with method arguments, and most likely others.

glenfarclas17 avatar Dec 16 '21 20:12 glenfarclas17

👋 We're looking to upgrade to ruby 3+ for one of our projects that uses ruby-jss but are hitting some failing tests. One of our devs noticed this open issue so I just wanted to follow up to see if there was any progress!

Hope all is well :)

marekluban avatar Apr 13 '22 19:04 marekluban

Heya Marek!

I'm currently working on ruby-jss v2.0.0, which is a major re-factor, and which I plan to have ruby 3.x support before is released. Keep your eye out in macadmins slack, I'm probably going to make a #ruby-jss channel very soon and invite everyone I know who uses it so we can discuss all the upcoming changes and do better debugging.

Thanks for the reminder!

PS feel free to send any backtrace or other details about failures you're seeing in ruby 3.x now. Thanks!

glenfarclas17 avatar Apr 13 '22 20:04 glenfarclas17

Hey @glenfarclas17 👋 ,

Thanks a ton for responding so quick to Marek :)

As follow up to @marekluban -- here is an example of what we are getting:

[3] pry(JamfClient)> JSS::AdvancedComputerSearch.fetch({:id=>72})
ArgumentError: wrong number of arguments (given 1, expected 0)
from /Users/jeffbrown/.gem/ruby/3.1.2/gems/ruby-jss-1.6.4/lib/jss/api_object.rb:1093:in `initialize'

Rails version: 7.0.2.3 Ruby Version:3.1.2 ruby-jss Version: 1.6.4

If I'm not mistaken I believe this is due to changes with keyword arguments in Ruby 3: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

jeffreyjbrown avatar Apr 13 '22 22:04 jeffreyjbrown

Hi @jeffreyjbrown !

First off, try using this when passing hashes into ruby 3 methods: JSS::AdvancedComputerSearch.fetch(**{:id=>72}) or pass them as keyword params JSS::AdvancedComputerSearch.fetch(id: 72)

However that still requires the method itself to be written properly :-) And to that end...

Have a look at the new 2.0.0-dev branch, just pushed yesterday: https://github.com/PixarAnimationStudios/ruby-jss/blob/v2.0.0-dev/README-2.0.0.md

I'm sure there's still lots of work to be done getting it all working in ruby 3, in fact I see that JSS::AdvancedComputerSearch.fetch id: 1003 is currently broken. I'll take a look at that this afternoon as I dive into getting all the Classic API objects updated.

Cheers! -Chris

glenfarclas17 avatar Apr 22 '22 21:04 glenfarclas17

Just found and fixed that one: needed a '**' when instantiating Criteriable::Criterion objects. It is now in GitHub and RubyGems.org as v2.0.0a11 My local test results pasted below (I haven't expanded the testing of Advanced Searches yet- but it did successfull .fetch one)
Also, I created a #ruby-jss channel in macadmins slack - feel free to join in the conversation there if you want to, as I work on v2.0.0.

Cheers! -Chris

>>>>> Starting tests of ruby-jss v2.0.0a11, using ruby version 3.1.1
>>>>> API Connection: [email protected]:8443, name: default; Server running Jamf Pro 10.37.2

>>>>> Running test advanced_computer_search.rb: 
- JamfTest::AdvancedComputerSearch --> Ran Jamf::AdvancedComputerSearch.all
- JamfTest::AdvancedComputerSearch --> Hash has key 'id'
- JamfTest::AdvancedComputerSearch --> Value '1107' for key 'id' is a Integer
- JamfTest::AdvancedComputerSearch --> Ran Jamf::AdvancedComputerSearch.all_ids
- JamfTest::AdvancedComputerSearch --> Ran Jamf::AdvancedComputerSearch.all_names
- JamfTest::AdvancedComputerSearch --> Ran Jamf::AdvancedComputerSearch.all_ids cached_list: @cached_all
- JamfTest::AdvancedComputerSearch --> Ran legacy Jamf::Policy.map_all_ids_to :name, :refresh
- JamfTest::AdvancedComputerSearch --> Ran modern Jamf::Policy.map_all :id, to: :name
- JamfTest::AdvancedComputerSearch --> Ran legacy Jamf::Policy.map_all_ids_to :name, cached_list: @cached_all
- JamfTest::AdvancedComputerSearch --> Ran modern Jamf::Policy.map_all :id, to: :name, cached_list: @cached_all
- JamfTest::AdvancedComputerSearch --> Jamf::AdvancedComputerSearch.valid_id for name 'chrisltest' returned the correct id
- JamfTest::AdvancedComputerSearch --> Ran Jamf::AdvancedComputerSearch.fetch random: true 
- JamfTest::AdvancedComputerSearch --> Done! Congrats, JamfTest::AdvancedComputerSearch looks good!

>>>>> Running test advanced_mobile_device_search.rb: 
- JamfTest::AdvancedMobileDeviceSearch --> Ran Jamf::AdvancedMobileDeviceSearch.all
- JamfTest::AdvancedMobileDeviceSearch --> Hash has key 'id'
- JamfTest::AdvancedMobileDeviceSearch --> Value '1760' for key 'id' is a Integer
- JamfTest::AdvancedMobileDeviceSearch --> Ran Jamf::AdvancedMobileDeviceSearch.all_ids
- JamfTest::AdvancedMobileDeviceSearch --> Ran Jamf::AdvancedMobileDeviceSearch.all_names
- JamfTest::AdvancedMobileDeviceSearch --> Ran Jamf::AdvancedMobileDeviceSearch.all_ids cached_list: @cached_all
- JamfTest::AdvancedMobileDeviceSearch --> Ran legacy Jamf::Policy.map_all_ids_to :name, :refresh
- JamfTest::AdvancedMobileDeviceSearch --> Ran modern Jamf::Policy.map_all :id, to: :name
- JamfTest::AdvancedMobileDeviceSearch --> Ran legacy Jamf::Policy.map_all_ids_to :name, cached_list: @cached_all
- JamfTest::AdvancedMobileDeviceSearch --> Ran modern Jamf::Policy.map_all :id, to: :name, cached_list: @cached_all
- JamfTest::AdvancedMobileDeviceSearch --> Jamf::AdvancedMobileDeviceSearch.valid_id for name 'chrisltest' returned the correct id
- JamfTest::AdvancedMobileDeviceSearch --> Ran Jamf::AdvancedMobileDeviceSearch.fetch random: true 
- JamfTest::AdvancedMobileDeviceSearch --> Done! Congrats, JamfTest::AdvancedMobileDeviceSearch looks good!

>>>>> Running test advanced_user_search.rb: 
- JamfTest::AdvancedUserSearch --> Ran Jamf::AdvancedUserSearch.all
- JamfTest::AdvancedUserSearch --> Hash has key 'id'
- JamfTest::AdvancedUserSearch --> Value '171' for key 'id' is a Integer
- JamfTest::AdvancedUserSearch --> Ran Jamf::AdvancedUserSearch.all_ids
- JamfTest::AdvancedUserSearch --> Ran Jamf::AdvancedUserSearch.all_names
- JamfTest::AdvancedUserSearch --> Ran Jamf::AdvancedUserSearch.all_ids cached_list: @cached_all
- JamfTest::AdvancedUserSearch --> Ran legacy Jamf::Policy.map_all_ids_to :name, :refresh
- JamfTest::AdvancedUserSearch --> Ran modern Jamf::Policy.map_all :id, to: :name
- JamfTest::AdvancedUserSearch --> Ran legacy Jamf::Policy.map_all_ids_to :name, cached_list: @cached_all
- JamfTest::AdvancedUserSearch --> Ran modern Jamf::Policy.map_all :id, to: :name, cached_list: @cached_all
- JamfTest::AdvancedUserSearch --> Jamf::AdvancedUserSearch.valid_id for name 'chrisltest' returned the correct id
- JamfTest::AdvancedUserSearch --> Ran Jamf::AdvancedUserSearch.fetch random: true 
- JamfTest::AdvancedUserSearch --> Done! Congrats, JamfTest::AdvancedUserSearch looks good!

glenfarclas17 avatar Apr 22 '22 21:04 glenfarclas17

Gonna close this one out, since v2.x and above have been tested to work (at least mostly) in ruby 3.0 and 3.1. If you find specific problems, please open a new issue for them. Thanks!

glenfarclas17 avatar Aug 08 '23 19:08 glenfarclas17