MCPcopy Index your code
hub / github.com/coder/coder / ExistsViaCoderConnect

Function ExistsViaCoderConnect

codersdk/workspacesdk/workspacesdk.go:436–462  ·  view source on GitHub ↗

ExistsViaCoderConnect checks if the given hostname exists via Coder Connect. This doesn't guarantee the workspace is actually reachable, if, for example, its agent is unhealthy, but rather that Coder Connect knows about the workspace and advertises the hostname via DNS.

(ctx context.Context, hostname string)

Source from the content-addressed store, hash-verified

434// workspace is actually reachable, if, for example, its agent is unhealthy, but rather that Coder Connect knows about
435// the workspace and advertises the hostname via DNS.
436func ExistsViaCoderConnect(ctx context.Context, hostname string) (bool, error) {
437 resolver := testOrDefaultResolver(ctx)
438 var dnsError *net.DNSError
439 ips, err := resolver.LookupIP(ctx, "ip6", hostname)
440 if xerrors.As(err, &dnsError) {
441 if dnsError.IsNotFound {
442 return false, nil
443 }
444 }
445 if err != nil {
446 return false, xerrors.Errorf("lookup DNS %s: %w", hostname, err)
447 }
448
449 // The returned IP addresses are probably from the Coder Connect DNS server, but there are sometimes weird captive
450 // internet setups where the DNS server is configured to return an address for any IP query. So, to avoid false
451 // positives, check if we can find an address from our service prefix.
452 for _, ip := range ips {
453 addr, ok := netip.AddrFromSlice(ip)
454 if !ok {
455 continue
456 }
457 if tailnet.CoderServicePrefix.AsNetip().Contains(addr) {
458 return true, nil
459 }
460 }
461 return false, nil
462}

Callers 3

existsCmdMethod · 0.92
sshMethod · 0.92
IsCoderConnectRunningMethod · 0.85

Calls 6

testOrDefaultResolverFunction · 0.85
AsMethod · 0.80
AsNetipMethod · 0.80
LookupIPMethod · 0.65
ErrorfMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected