MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / buildCommunityScriptPlan

Function buildCommunityScriptPlan

internal/cli/community_scripts.go:348–413  ·  view source on GitHub ↗
(cmd *cobra.Command, nameOrSlug string)

Source from the content-addressed store, hash-verified

346}
347
348func buildCommunityScriptPlan(cmd *cobra.Command, nameOrSlug string) (*communityScriptPlanOutput, error) {
349 session, err := initCLISession(cmd)
350 if err != nil {
351 return nil, err
352 }
353 if session == nil {
354 return nil, nil
355 }
356 if err := ensureCommunityScriptsEnabled(session); err != nil {
357 return nil, err
358 }
359
360 nodeName, _ := cmd.Flags().GetString("node")
361 env, err := parseCommunityScriptEnvFlags(cmd)
362 if err != nil {
363 return nil, err
364 }
365
366 ctx := context.Background()
367 node, err := session.findNodeByName(ctx, nodeName)
368 if err != nil {
369 return nil, err
370 }
371 if !node.Online {
372 return nil, fmt.Errorf("node %q is offline", nodeName)
373 }
374
375 script, err := findCommunityScript(nameOrSlug)
376 if err != nil {
377 return nil, err
378 }
379 if err := validateCommunityScriptInstall(script); err != nil {
380 return nil, err
381 }
382
383 sshUser, _ := session.resolveNodeSSHCreds(node)
384 if sshUser == "" {
385 return nil, fmt.Errorf("SSH user not configured; set ssh_user in config or use --ssh-user")
386 }
387
388 host := node.IP
389 if host == "" {
390 host = node.Name
391 }
392
393 redactedEnv := redactCommunityScriptEnv(env)
394 preset := ""
395 if communityScriptNonInteractive(cmd) {
396 preset = "default"
397 }
398
399 remoteCmd, err := core.BuildRemoteInstallCommand(sshUser, script, redactedEnv, preset)
400 if err != nil {
401 return nil, err
402 }
403
404 return &communityScriptPlanOutput{
405 Node: node.Name,

Callers 1

runCommunityScriptsPlanFunction · 0.85

Calls 10

initCLISessionFunction · 0.85
findCommunityScriptFunction · 0.85
redactCommunityScriptEnvFunction · 0.85
communityScriptToOutputFunction · 0.85
findNodeByNameMethod · 0.80
resolveNodeSSHCredsMethod · 0.80

Tested by

no test coverage detected