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

Feat/scaleway.com #899

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

Conversation

francesco086
Copy link

Solves issue #660

@francesco086 francesco086 mentioned this pull request Jan 1, 2025
@francesco086
Copy link
Author

Regarding the change in the markdown tables: I use the VSCode formatter https://marketplace.visualstudio.com/items?itemName=fcrespo82.markdown-table-formatter

Do you want me to reverse the markdown table back to the original state?

Copy link
Owner

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

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

Thanks 👍 !

Two important things are to remove the field_type and field_name, unless there is reason I'm not aware of 😉

README.md Outdated
Comment on lines 37 to 38
| Version | Readme link | Docs link |
|---------|-----------------------------------------------------------------------|-----------------------------------------------------------------|
Copy link
Owner

Choose a reason for hiding this comment

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

Yeah let's revert this otherwise the git history is going to look all weird; Note you can open the vscode command palette and hit "save without formatting" 😉

I would however be okay with a separate PR to auto-format this + perhaps enforce this in the CI 🤔

Copy link
Author

Choose a reason for hiding this comment

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

done 😄

I am happy to do this in a separate PR. I am not sure of a way to enforce this in CI, but I guess there must be a way.

Copy link
Owner

Choose a reason for hiding this comment

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

Have a look at the .github/workflows/markdown.yml there might be rules you can set in the linter 😉

Copy link
Author

Choose a reason for hiding this comment

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

I opened an issue #908 (comment)

Will be happy to contribute 😄

docs/scaleway.md Outdated Show resolved Hide resolved
docs/scaleway.md Outdated
- `"ip_version"` can be `"ipv4"` or `"ipv6"`. It defaults to `"ipv4"`.
- `"ipv6_suffix"` is the suffix to append to the IPv6 address. It defaults to `""`.
- `"field_type"` is the type of DNS record to update. It can be `"A"` or `"AAAA"`. It defaults to `"A"`.
- `"field_name"` is the name of the DNS record to update. For example, it could be `"www"`, `"@"` or `"*"` for the wildcard. It defaults to to `""` (equivalent to `"@"`).
Copy link
Owner

Choose a reason for hiding this comment

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

You should not need this, it should be deducted from the "domain" field

Copy link
Author

Choose a reason for hiding this comment

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

Please help me out here. How should I extract this? The only way I can imagine is to count how many . are in the domain string, and if there are two take the first part of the domain string before the first . as name (according to the scaleway API). Is that correct?

Copy link
Owner

Choose a reason for hiding this comment

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

The upper layers of ddns-updater takes care of extracting it:

func extractFromDomainField(domainField string) (domainRegistered string,

It's a bit more complicated than the number of dots, it uses the "effective TLD + 1" mechanism to do this (i.e. some effective TLDs are com., others are duckdns.org.)

So just use the domain and owner strings from calling layers 😉 - it's already parsed and ready to use for you.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, it took me a while to understand what you mean and especialyl how this maps to the scaleway api, but I think I sorted out! I removed the field_name both in the code and documentation, and tested that everything works correctly.

docs/scaleway.md Outdated

- `"ip_version"` can be `"ipv4"` or `"ipv6"`. It defaults to `"ipv4"`.
- `"ipv6_suffix"` is the suffix to append to the IPv6 address. It defaults to `""`.
- `"field_type"` is the type of DNS record to update. It can be `"A"` or `"AAAA"`. It defaults to `"A"`.
Copy link
Owner

Choose a reason for hiding this comment

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

You should not need this, it should be deducted from the public IP address obtained and "ip_version"

Copy link
Author

Choose a reason for hiding this comment

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

Uhm... again can you help me here? Do you have already a function that is able to distinguish between the two?

Copy link
Author

Choose a reason for hiding this comment

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

I just found it in one of your comment below. Will change this in a moment!

Copy link
Author

Choose a reason for hiding this comment

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

done

Copy link
Owner

Choose a reason for hiding this comment

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

field_type is still in the documentation 😉 Please remove 🙏

Copy link
Author

Choose a reason for hiding this comment

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

argh sorry... missed the second entry...

Now it is removed for good!

internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
Comment on lines 180 to 188
s, err := utils.ReadAndCleanBody(response.Body)
if err != nil {
return netip.Addr{}, fmt.Errorf("reading response: %w", err)
}

if response.StatusCode != http.StatusOK {
return netip.Addr{}, fmt.Errorf("%w: %d: %s",
errors.ErrHTTPStatusNotValid, response.StatusCode, utils.ToSingleLine(s))
}
Copy link
Owner

Choose a reason for hiding this comment

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

is there any useful information in the body? if it's just for the error case, let's use instead:

Suggested change
s, err := utils.ReadAndCleanBody(response.Body)
if err != nil {
return netip.Addr{}, fmt.Errorf("reading response: %w", err)
}
if response.StatusCode != http.StatusOK {
return netip.Addr{}, fmt.Errorf("%w: %d: %s",
errors.ErrHTTPStatusNotValid, response.StatusCode, utils.ToSingleLine(s))
}
if response.StatusCode != http.StatusOK {
return netip.Addr{}, fmt.Errorf("%w: %d: %s",
errors.ErrHTTPStatusNotValid, response.StatusCode, utils.BodyToSingleLine(response.Body))
}

Copy link
Author

Choose a reason for hiding this comment

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

the body looks something like

{
    "records": [
        {
            "id": "aa051759-72e6-4034-8af5-dafba3eebb79",
            "data": "127.1.2.3",
            "name": "",
            "priority": 0,
            "ttl": 300,
            "type": "A",
            "comment": null
        }
    ]
}

I think there is nothing useful, let me know if you disagree. Otherwise I will apply your change.

Copy link
Owner

Choose a reason for hiding this comment

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

What happens if you send a request with the wrong secret key or an owner that doesn't exist, what's the json body you get in the response? It might be a standardized error format which we could parse and use to build a better error to log to the user 😉 Not compulsory, but nice to have if you have the time

Copy link
Author

Choose a reason for hiding this comment

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

if the secret key is wrong the response is:

{
    "message": "authentication is denied",
    "method": "api_key",
    "reason": "invalid_argument",
    "type": "denied_authentication"
}

If the owner doesn't exist then the record with the right domain is added. The response is indistinguishable from one where the owner already exists.

So, I changed the code into:

if response.StatusCode != http.StatusOK {
		var errorResponse struct {
			Message string `json:"message"`
			Type    string `json:"type"`
		}
		if jsonErr := json.Unmarshal([]byte(s), &errorResponse); jsonErr == nil {
			if errorResponse.Type == "denied_authentication" {
				return netip.Addr{}, fmt.Errorf("%w: %s", errors.ErrAuth, errorResponse.Message)
			}
		}
		return netip.Addr{}, fmt.Errorf("%w: %d: %s",
			errors.ErrHTTPStatusNotValid, response.StatusCode, utils.ToSingleLine(s))
	}

Is that ok?

@francesco086 francesco086 requested a review from qdm12 January 2, 2025 08:18
@francesco086
Copy link
Author

Hi @qdm12 , any chance for a second round of review?

Copy link
Owner

@qdm12 qdm12 left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, I've been quite away from (personal open source) keyboard because of work/life/travels 😄

docs/scaleway.md Outdated Show resolved Hide resolved
docs/scaleway.md Outdated Show resolved Hide resolved
docs/scaleway.md Outdated

- `"ip_version"` can be `"ipv4"` or `"ipv6"`. It defaults to `"ipv4"`.
- `"ipv6_suffix"` is the suffix to append to the IPv6 address. It defaults to `""`.
- `"field_type"` is the type of DNS record to update. It can be `"A"` or `"AAAA"`. It defaults to `"A"`.
Copy link
Owner

Choose a reason for hiding this comment

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

field_type is still in the documentation 😉 Please remove 🙏

internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
internal/provider/providers/scaleway/provider.go Outdated Show resolved Hide resolved
Path: fmt.Sprintf("/domain/v2beta1/dns-zones/%s/records", p.domain),
}

field_type := "A"
Copy link
Owner

Choose a reason for hiding this comment

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

nit rename to fieldType (Go convention is no snake_case 🤷 Only camelCase)

Copy link
Author

Choose a reason for hiding this comment

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

true! Should have noticed... changed accordingly!

Comment on lines 180 to 188
s, err := utils.ReadAndCleanBody(response.Body)
if err != nil {
return netip.Addr{}, fmt.Errorf("reading response: %w", err)
}

if response.StatusCode != http.StatusOK {
return netip.Addr{}, fmt.Errorf("%w: %d: %s",
errors.ErrHTTPStatusNotValid, response.StatusCode, utils.ToSingleLine(s))
}
Copy link
Owner

Choose a reason for hiding this comment

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

What happens if you send a request with the wrong secret key or an owner that doesn't exist, what's the json body you get in the response? It might be a standardized error format which we could parse and use to build a better error to log to the user 😉 Not compulsory, but nice to have if you have the time

@francesco086
Copy link
Author

Hi @qdm12 ! I had a feeling that perhaps you were on holidays, this is why I waited... after a week I tried my luck 😃

Alright, I think I addressed all your concerns and hope that it is ready to merge now. Perhaps let me bring you attention to these changes in particular. It took me a while to figure this out, and this is why I thought it would be useful to document them. But perhaps it's just me, I am not familiar with DNS and networking terminologies (I studied physics), I am trying to learn as a hobby. So, let me know your opinion.

@francesco086 francesco086 requested a review from qdm12 January 11, 2025 15:17
@francesco086
Copy link
Author

Hi @qdm12 , time for a third review? I believe the PR is ready to be merged now

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.

2 participants