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

Add support for the Certbot Gandi plugin #295

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

cible
Copy link
Contributor

@cible cible commented Aug 26, 2022

Pull Request (PR) description

Adding feature support for the certbot-plugin-gandi created by @obynio

The plugin use the Production API key.

This Pull Request (PR) fixes the following issues

N/A

@@ -5,3 +5,4 @@ letsencrypt::cron_owner_group: 'wheel'
letsencrypt::plugin::dns_rfc2136::package_name: 'py38-certbot-dns-rfc2136'
letsencrypt::plugin::dns_route53::package_name: 'py38-certbot-dns-route53'
letsencrypt::plugin::dns_cloudflare::package_name: 'py38-certbot-dns-cloudflare'
letsencrypt::plugin::dns_gandi::package_name: 'certbot-plugin-gandi'
Copy link
Member

Choose a reason for hiding this comment

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

There are currently no FreeBSD port for this :-/

The name would probably be py38-certbot-dns-gandi if there was, and in fact py39-certbot-dns-gandi because the default version of Python changed recently on FreeBSD.

Copy link
Member

Choose a reason for hiding this comment

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

I opened #296 to adjust the FreeBSD version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it's a good idea to install the package with pip? I'm not sure on how to install them on freebsd and centos. I will ask help to a colleague

Copy link
Member

Choose a reason for hiding this comment

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

As a FreeBSD user, I would prefer to use a package rather installing using pip. Anybody can submit ports to FreeBSD, and they are ultimately available as packages. My guess is that if the port does not exist, nobody needed it so much they did a port for it, and maybe it is not worth it?

I would personally not set a package_name for FreeBSD in Hiera and make $letsencrypt::plugin::dns_gandi::package_name mandatory so that it fails hard if someone attempt to use it on FreeBSD.

@@ -0,0 +1,3 @@
---
letsencrypt::plugin::dns_gandi::package_provider: apt
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to set the package provider? That's rarely needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I will remove it

Comment on lines 25 to 35
if $package_provider {
package { $package_name:
ensure => installed,
provider => $package_provider,
}
}
else {
package { $package_name:
ensure => installed,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

You can just pass undef along:

Suggested change
if $package_provider {
package { $package_name:
ensure => installed,
provider => $package_provider,
}
}
else {
package { $package_name:
ensure => installed,
}
}
package { $package_name:
ensure => installed,
provider => $package_provider,
}

Comment on lines 38 to 44
if $api_key {
$ini_vars = {
'certbot_plugin_gandi:dns_api_key' => $api_key,
}
} else {
fail('api_key not provided for certbot dns gandi plugin.')
}
Copy link
Member

Choose a reason for hiding this comment

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

The data type guarantees it's set

Suggested change
if $api_key {
$ini_vars = {
'certbot_plugin_gandi:dns_api_key' => $api_key,
}
} else {
fail('api_key not provided for certbot dns gandi plugin.')
}
$ini_vars = {
'certbot_plugin_gandi:dns_api_key' => $api_key,
}

@@ -3,3 +3,4 @@ letsencrypt::configure_epel: true
letsencrypt::plugin::dns_rfc2136::package_name: 'python3-certbot-dns-rfc2136'
letsencrypt::plugin::dns_route53::package_name: 'python3-certbot-dns-route53'
letsencrypt::plugin::dns_cloudflare::package_name: 'python3-certbot-dns-cloudflare'
letsencrypt::plugin::dns_gandi::package_name: 'certbot-plugin-gandi'
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't look correct.

@treydock treydock requested review from ekohl and smortex November 16, 2022 18:33
@treydock
Copy link
Contributor

@cible Is this ready for review? The pull request is currently marked as a draft.

@treydock treydock added the enhancement New feature or request label Nov 16, 2022
manifests/plugin/dns_gandi.pp Outdated Show resolved Hide resolved
class letsencrypt::plugin::dns_gandi (
String[1] $api_key,
String[1] $package_name,
Optional[String[1]] $package_provider = undef,
Copy link
Member

Choose a reason for hiding this comment

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

This is an unused parameter. Shouldn't it be passed to the package resource?

manifests/plugin/dns_gandi.pp Outdated Show resolved Hide resolved
spec/spec_helper_acceptance.rb Show resolved Hide resolved
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>

it do
if package_name.nil?
is_expected.not_to compile
Copy link
Member

Choose a reason for hiding this comment

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

A better way is to test for the error:

Suggested change
is_expected.not_to compile
is_expected.to compile.and_raise_error(/A Matcher For The Error/)

PUPPET
end

it { is_expected.not_to compile.with_all_deps }
Copy link
Member

Choose a reason for hiding this comment

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

Here too it's better to compile and test for a specific error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this one, the module won't work with an empty api_key and I don't know how to handle the error:

  13) letsencrypt::certonly on fedora-36-x86_64 based operating systems with dns-gandi plugin without api_key is expected to fail to compile and raise an error matching /\/expects a value for parameter 'api_key'\//
      Failure/Error: it { is_expected.to compile.and_raise_error(%r{/expects a value for parameter 'api_key'/}) }
        error during compilation: Evaluation Error: Error while evaluating a Resource Statement, Class[Letsencrypt::Plugin::Dns_gandi]: expects a value for parameter 'api_key' (line: 6, column: 11

it { is_expected.to compile.and_raise_error(%r{/expects a value for parameter 'api_key'/}) } is not correct?

Copy link
Member

Choose a reason for hiding this comment

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

The / is redundant. In Ruby you can define a regex as /my regex/ or %r{my regex} but %r{/my regex/} means you expect / in the output. This is useful if you want to test /var/lib is empty is in the error. Compare %r{/var/lib is empty} to /\/var\/lib is empty/.

manifests/plugin/dns_gandi.pp Outdated Show resolved Hide resolved
spec/classes/plugin/dns_gandi_spec.rb Outdated Show resolved Hide resolved
spec/classes/plugin/dns_gandi_spec.rb Outdated Show resolved Hide resolved
spec/classes/plugin/dns_gandi_spec.rb Outdated Show resolved Hide resolved
@cible
Copy link
Contributor Author

cible commented Nov 23, 2022

It seem ok for me. Sorry for being so slow and bad with ruby. Did I have to do something else? rebase?

@cible cible marked this pull request as ready for review November 23, 2022 14:58
@bastelfreak
Copy link
Member

@cible yes, this needs a rebase. I think we can merge if afterwards 👍

@kenyon kenyon changed the title Adding feature support for the Certbot plugin Gandi Add support for the Certbot Gandi plugin Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants