-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
base: master
Are you sure you want to change the base?
Feat/scaleway.com #899
Conversation
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? |
There was a problem hiding this 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
| Version | Readme link | Docs link | | ||
|---------|-----------------------------------------------------------------------|-----------------------------------------------------------------| |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😉
There was a problem hiding this comment.
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
- `"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 `"@"`). |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
ddns-updater/internal/params/json.go
Line 231 in 20ac110
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.
There was a problem hiding this comment.
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"`. |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
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 🙏
There was a problem hiding this comment.
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!
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)) | ||
} |
There was a problem hiding this comment.
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:
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)) | |
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
Hi @qdm12 , any chance for a second round of review? |
There was a problem hiding this 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
|
||
- `"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"`. |
There was a problem hiding this comment.
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 🙏
Path: fmt.Sprintf("/domain/v2beta1/dns-zones/%s/records", p.domain), | ||
} | ||
|
||
field_type := "A" |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
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)) | ||
} |
There was a problem hiding this comment.
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
Co-authored-by: Quentin McGaw <[email protected]>
Co-authored-by: Quentin McGaw <[email protected]>
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. |
Hi @qdm12 , time for a third review? I believe the PR is ready to be merged now |
Solves issue #660