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

Sub domain replace feature #307

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

Conversation

charlieporth1
Copy link
Collaborator

@charlieporth1 charlieporth1 commented May 2, 2023

No doc or unit test done yet will provide when time is abundant

Copy link
Owner

@folbricht folbricht left a comment

Choose a reason for hiding this comment

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

Does this actually do anything that the existing "replace" doesn't? https://github.com/folbricht/routedns/blob/master/doc/configuration.md#Replace looks more flexible as it's possible to replace any part of the domain using regexes

cmd/routedns/example-config/subdomain-replace.toml Outdated Show resolved Hide resolved
subdomain-replace.go Outdated Show resolved Hide resolved
subdomain-replace.go Outdated Show resolved Hide resolved
subdomain-replace.go Outdated Show resolved Hide resolved
@charlieporth1
Copy link
Collaborator Author

charlieporth1 commented May 3, 2023

Does this actually do anything that the existing "replace" doesn't? https://github.com/folbricht/routedns/blob/master/doc/configuration.md#Replace looks more flexible as it's possible to replace any part of the domain using regexes

No, it doesn't but it is simpler & faster which is why I created it

Copy link
Owner

@folbricht folbricht left a comment

Choose a reason for hiding this comment

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

One thing I'm not to fond of is the same. This isn't replacing "sub"-domains, but actually it's replacing domains. Should this be called domain-replace perhaps?

Also, could you add a section to the documentation? This is effectively a more efficient and simple replacing group, faster than the regexp replacer.

exp = append(exp, subDomainReplaceExp{o.From, o.To})
} else {
return nil, errors.New("{} not found")
}
Copy link
Owner

Choose a reason for hiding this comment

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

Do you still need this since {} isn't necessary in the config anymore?

func (r subDomainReplaceExp) substitute(qname string) (string, bool) {
fromDomain := r.from
toDomain := r.to
// from {}.ctptech.dev to {}.charlesp.tech
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
// from {}.ctptech.dev to {}.charlesp.tech
// from .ctptech.dev to .charlesp.tech

Comment on lines +37 to +39
} else {
return "", false
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
} else {
return "", false
}
}
return "", false

// from {}.ctptech.dev to {}.charlesp.tech
// from test.ctptech.dev to test.charlesp.tech
if strings.HasSuffix(qname, fromDomain) {
str := strings.Replace(qname, fromDomain, toDomain, 1)
Copy link
Owner

Choose a reason for hiding this comment

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

I think there's a small issue with just doing a simple replace since the "fromDomain" string can show up more than once in the domain. Let's say you have fromDomain = .local. and the domain name being looked up is example.local.something.local. then it'd replace the first occurrance. It might be best to simply strip the fromDomain with strings.TrimSuffix(), then add the toDomain value to the result with + like so:

sub := strings.TrimSuffix(qname, fromDomain)
str := sub+toDomain
return str, true

@charlieporth1
Copy link
Collaborator Author

charlieporth1 commented May 16, 2023

For sure
My vision with the brackets was that you could use {}/{1} similar to how gnu parallel works

@folbricht
Copy link
Owner

If you want to use {}, it'd make sense to change the behavior of the replacing logic and allow replacing in any position, not just at the front of the name. Otherwise using {} is confusing since it looks like one can place it anywhere, but it's only really supported in one place, and only a single instance.

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.

None yet

2 participants