Skip to content
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

Cannot use action_class methods #85

Open
Lasering opened this issue May 4, 2023 · 5 comments
Open

Cannot use action_class methods #85

Lasering opened this issue May 4, 2023 · 5 comments

Comments

@Lasering
Copy link

Lasering commented May 4, 2023

πŸ‘» Brief Description

action_class methods cannot be invoked

πŸ₯ž Cookbook version

2.0.16

πŸ‘©β€πŸ³ Chef-Infra Version

18

🎩 Platform details

CentOS 7
AlmaLinux 8

Steps To Reproduce

consul_certificate = certificate_manage 'consul-server' do
  data_bag 'service-discovery'
  data_bag_secret Chef::Config['encrypted_data_bag_secret']

  create_subfolders false
  cert_path '/etc/consul/ssl'

  action :create
end

print(consul_certificate.key_path)
print(consul_certificate.key) # as documented in the readme section ".certificate, .key, .chain helper method usage"

Fails with:

NoMethodError
-------------
undefined method `key_path' for Custom resource certificate_manage from cookbook certificate

πŸš“ Expected behavior

The correct path should be printed.

βž• Additional context

The key_path is being used in other resources.
This error occurs when using a kitchen converge.

@ramereth
Copy link
Contributor

ramereth commented May 4, 2023

I don't believe the methods in action_class are intended to be used outside of the resource.

@Lasering
Copy link
Author

Lasering commented May 5, 2023

I searched whether that was true or not but couldn't find anything. So if that is the case then the documentation is misleading, and the cookbook "loses" some functionality. I propose moving those methods out of the action_class this way they would be available outside and inside the actions. I can make a PR is this would be accepted.

@Lasering
Copy link
Author

Lasering commented May 5, 2023

Have a look at this cookbook https://github.com/ist-dsi/cookbook-vault-certificate. The resource vault_certificate has both action_class and "direct methods" on the resource promoting code reuse not only on the resource implementation but on the chef recipe where the resource is being used

@ramereth
Copy link
Contributor

ramereth commented May 5, 2023

If we move these into a helper library, it would be more visible. That might be more portable anyway and what we've been doing on other cookbooks. Feel free to create a PR which does this so you can restore the functionality.

@Lasering
Copy link
Author

Lasering commented May 6, 2023

Can you point me to a cookbook where that is being done?

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

No branches or pull requests

2 participants