MCPcopy
hub / github.com/lxc/incus / run

Method run

cmd/incus/remote.go:406–725  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

404}
405
406func (c *cmdRemoteAdd) run(cmd *cobra.Command, args []string) error {
407 conf := c.global.conf
408
409 // Do NOT blindly copy the following parsing line; it is a dirty hack to disambiguate the parser.
410 parsed, err := c.global.Parse(cmdRemoteAddUsage, cmd, args, len(args) == 1)
411 if err != nil {
412 return err
413 }
414
415 target := parsed[1].String
416 addrs := parsed[1].StringList
417 server := parsed[0].Get(target)
418
419 // Validate the server name.
420 if strings.Contains(server, ":") {
421 if parsed[0].Skipped {
422 return errors.New(i18n.G("Remote names may not contain colons; please provide an explicit one"))
423 }
424
425 return errors.New(i18n.G("Remote names may not contain colons"))
426 }
427
428 // Check for existing remote
429 remote, ok := conf.Remotes[server]
430 if ok {
431 return fmt.Errorf(i18n.G("Remote %s already exists"), server)
432 }
433
434 // Initialize the remotes list if needed
435 if conf.Remotes == nil {
436 conf.Remotes = map[string]config.Remote{}
437 }
438
439 rawToken, err := localtls.CertificateTokenDecode(target)
440 if err == nil {
441 return c.runToken(server, target, rawToken)
442 }
443
444 // Fast track image servers.
445 if slices.Contains([]string{"oci", "simplestreams"}, c.flagProtocol) {
446 for _, addr := range addrs {
447 remoteURL, err := url.Parse(addr)
448 if err != nil || remoteURL.Scheme != "https" {
449 return errors.New(i18n.G("Only https URLs are supported for oci and simplestreams"))
450 }
451 }
452
453 conf.Remotes[server] = config.Remote{
454 Addrs: addrs,
455 Public: true,
456 Protocol: c.flagProtocol,
457 KeepAlive: c.flagKeepAlive,
458 CredHelper: c.flagCredHelper,
459 }
460
461 return conf.SaveConfig(c.global.confPath)
462 } else if c.flagProtocol != "incus" {
463 return fmt.Errorf(i18n.G("Invalid protocol: %s"), c.flagProtocol)

Callers

nothing calls this directly

Calls 15

runTokenMethod · 0.95
findProjectMethod · 0.95
GFunction · 0.92
normalizeAddressFunction · 0.85
ErrorfMethod · 0.80
SaveConfigMethod · 0.80
HasClientCertificateMethod · 0.80
GetImageServerMethod · 0.80
GetInstanceServerMethod · 0.80
ConfigPathMethod · 0.80
ServerCertPathMethod · 0.80

Tested by

no test coverage detected