MCPcopy Create free account
hub / github.com/docker/docker-agent / ParseExternalAgentRef

Function ParseExternalAgentRef

pkg/config/resolve.go:278–300  ·  view source on GitHub ↗

ParseExternalAgentRef parses an external agent reference that may include an explicit name prefix. The syntax is "name:reference" where name is a simple identifier (no slashes) and reference is an OCI reference or URL. If no explicit name is provided, the base name is derived from the reference: -

(input string)

Source from the content-addressed store, hash-verified

276// ParseExternalAgentRef("docker.io/myorg/myagent:v1") → ("myagent", "docker.io/myorg/myagent:v1")
277// ParseExternalAgentRef("https://example.com/agent.yaml") → ("agent", "https://example.com/agent.yaml")
278func ParseExternalAgentRef(input string) (agentName, ref string) {
279 // If the whole input is already a valid external reference, derive the name
280 // from it without trying to split on ":".
281 if isExternalRef(input) {
282 return externalRefBaseName(input), input
283 }
284
285 // Check for explicit "name:reference" syntax.
286 // A name prefix is identified by not containing "/" (distinguishing it from
287 // OCI references or URLs which always contain slashes).
288 if i := strings.Index(input, ":"); i > 0 {
289 candidate := input[:i]
290 if !strings.Contains(candidate, "/") {
291 remainder := input[i+1:]
292 if isExternalRef(remainder) {
293 return candidate, remainder
294 }
295 }
296 }
297
298 // Fallback: return input as both name and ref (for local agent names).
299 return input, input
300}
301
302// isExternalRef is the core check for whether a string is an external reference.
303// It is used by both IsExternalReference and ParseExternalAgentRef to avoid

Callers 5

resolveAgentRefsFunction · 0.92
validateConfigFunction · 0.85
validateForceHandoffsFunction · 0.85
IsExternalReferenceFunction · 0.85

Calls 2

isExternalRefFunction · 0.85
externalRefBaseNameFunction · 0.85

Tested by 1