Cannot use action_class methods
:ghost: Brief Description
action_class methods cannot be invoked
:pancakes: Cookbook version
2.0.16
:woman_cook: Chef-Infra Version
18
:tophat: 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
:police_car: Expected behavior
The correct path should be printed.
:heavy_plus_sign: Additional context
The key_path is being used in other resources. This error occurs when using a kitchen converge.
I don't believe the methods in action_class are intended to be used outside of the resource.
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.
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
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.
Can you point me to a cookbook where that is being done?