Skip to content

rewrite macos_userdefaults using corefoundation gem #11898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 17, 2021

Conversation

rishichawda
Copy link
Member

@rishichawda rishichawda commented Aug 4, 2021

Signed-off-by: rishichawda rishichawda@users.noreply.github.com

Rewrite of macos_userdefaults resource using the corefoundation gem.

Description

Replace usage of defaults command and use the preference interface from the corefoundation gem we're developing at corefoundation.

NOTE: The tests in the pipeline would currently fail for this PR since I'm developing it against a local version of the corefoundation gem. All updates are being tracked in PRs on the gem's repo. Once the required changes are released, we can update the Gemfile in this branch.

Related Issue

#10307
#10083
https://github.com/chef/desktop-config/issues/214

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@logwolvy
Copy link

logwolvy commented Aug 9, 2021

@rishichawda This POC code is already reviewed and could really help, #11785

@rishichawda
Copy link
Member Author

@logwolvy Yeah I had seen that code when the PR was raised and it was incorrect somewhere in the start itself so I didn't refer to it further. I did go through the thread in the PR though and kept those in mind while working on the resource. 😄

@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch 2 times, most recently from b7eaebf to b337b55 Compare August 9, 2021 18:37
@rishichawda rishichawda changed the title [WIP] rewrite macos_userdefaults using corefoundation gem rewrite macos_userdefaults using corefoundation gem Aug 9, 2021
@logwolvy
Copy link

@logwolvy Yeah I had seen that code when the PR was raised and it was incorrect somewhere in the start itself so I didn't refer to it further.

@rishichawda Could you point to that? Let's check if that works and re-use

@rishichawda
Copy link
Member Author

Yeah I think it was the method call in load current value at the start. That wouldn't work. Anyways, the resource has already been updated in this branch so it doesn't seem like a good use of time to go back to an old code and fix it when we don't need it anymore.

@logwolvy
Copy link

Yeah I think it was the method call in load current value at the start. That wouldn't work. Anyways, the resource has already been updated in this branch so it doesn't seem like a good use of time to go back to an old code and fix it when we don't need it anymore.

That POC code was working and already reviewed, so that was a head start anyway. Moving on, I recommend, checking/reusing as much as possible before starting out since we are time bound in development/review efforts.

@rishichawda rishichawda requested a review from a team September 14, 2021 05:40
Copy link

@logwolvy logwolvy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this would absolutely require kitchen tests

end
end

action :delete, description: "Delete a key from a domain." do
# if it's not there there's nothing to remove
return unless current_resource

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this need not be changed

end
end

action_class do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using action_class would make passing new_resource redundant, a good thing here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action_class context is not available to load_current_resource.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not referring to load_current_resource here

Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch 2 times, most recently from be057ab to 37cccb1 Compare September 24, 2021 20:27
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch 2 times, most recently from 468c998 to 162e387 Compare September 24, 2021 20:43
chef.gemspec Outdated
@@ -52,6 +52,7 @@ Gem::Specification.new do |s|
s.add_dependency "addressable"
s.add_dependency "syslog-logger", "~> 1.6"
s.add_dependency "uuidtools", ">= 2.1.5", "< 3.0" # osx_profile resource
s.add_dependency "corefoundation", "~> 0.3.4" # corefoundation framework utilities
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment should say where we're using it more than what it gives us.

# macos_userdefaults

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch from d521866 to c39731e Compare September 24, 2021 20:56
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Copy link
Member Author

@rishichawda rishichawda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 12aa62c to cover the test case for bug in #10083

end
def set_preference(new_resource)
CF::Preferences.set!(new_resource.key, new_resource.value, new_resource.domain, new_resource.user, new_resource.host)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think this method is getting used (might be causing some confusion over the action_class block)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah I might have overlooked this after I moved the call directly inside the action.. will remove this now.. Thank you!

Copy link
Member Author

@rishichawda rishichawda Sep 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the :write action was using this function but :delete was using the .set! method from CF directly. Changed the :write to also use set! method in 858cc22.

Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch from 2a96bf8 to 858cc22 Compare September 30, 2021 09:38
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch 2 times, most recently from 4d28605 to 6d61daa Compare October 1, 2021 19:45
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@rishichawda rishichawda force-pushed the api-based-macos-userdefaults branch from 6d61daa to 1b811ab Compare October 4, 2021 09:30
cmd
end
action_class do
require "corefoundation" if RUBY_PLATFORM.match?(/darwin/)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it work if this was declared at the top?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actions won't find the module then so it needs to go here 🤷🏻‍♂️

Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
Signed-off-by: rishichawda <rishichawda@users.noreply.github.com>
@tas50 tas50 merged commit 1217fad into main Oct 17, 2021
@tas50 tas50 deleted the api-based-macos-userdefaults branch October 17, 2021 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants