当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.SignAction方法代码示例

本文整理汇总了Golang中mig/client.Client.SignAction方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.SignAction方法的具体用法?Golang Client.SignAction怎么用?Golang Client.SignAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mig/client.Client的用法示例。


在下文中一共展示了Client.SignAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: actionLauncher


//.........这里部分代码省略.........
			if !hasEvaluatedTarget {
				agents, err := cli.EvaluateAgentTarget(a.Target)
				if err != nil {
					panic(err)
				}
				count := len(agents)
				if count == 0 {
					fmt.Println("0 agents match this target. launch aborted")
					break
				}
				fmt.Printf("%d agents will be targeted by search \"%s\"\n", count, a.Target)
				input, err = readline.String("continue? (y/n)> ")
				if err != nil {
					panic(err)
				}
				if input != "y" {
					fmt.Println("launch aborted")
					break
				}
			}
			if !hasTimes {
				fmt.Printf("Times are not defined. Setting validity from now until +%s\n", defaultExpiration)
				// for immediate execution, set validity one minute in the past
				a.ValidFrom = time.Now().Add(-60 * time.Second).UTC()
				period, err := time.ParseDuration(defaultExpiration)
				if err != nil {
					panic(err)
				}
				a.ExpireAfter = a.ValidFrom.Add(period)
				a.ExpireAfter = a.ExpireAfter.Add(60 * time.Second).UTC()
				hasTimes = true
			}
			if !hasSignatures {
				asig, err := cli.SignAction(a)
				if err != nil {
					panic(err)
				}
				a = asig
				hasSignatures = true
			}
			a, err = cli.PostAction(a)
			if err != nil {
				panic(err)
			}
			fmt.Printf("Action '%s' successfully launched with ID '%.0f' on target '%s'\n",
				a.Name, a.ID, a.Target)
			if follow {
				err = cli.FollowAction(a)
				if err != nil {
					panic(err)
				}
			}
			fmt.Println("")
			_ = actionReader(fmt.Sprintf("action %.0f", a.ID), cli)
			goto exit
		case "listagents":
			agents, err := cli.EvaluateAgentTarget(a.Target)
			if err != nil {
				fmt.Println(err)
				break
			}
			fmt.Println("----    ID      ---- + ----         Name         -------")
			for _, agt := range agents {
				fmt.Printf("%20.0f   %s\n", agt.ID, agt.Name)
			}
		case "load":
开发者ID:rayyang2000,项目名称:mig,代码行数:67,代码来源:action_launcher.go

示例2: main


//.........这里部分代码省略.........
	fs.SetOutput(os.NewFile(uintptr(87592), os.DevNull))
	err = fs.Parse(os.Args[2:])
	fs.SetOutput(nil)
	if err != nil {
		// ignore the flag not defined error, which is expected because
		// module parameters are defined in modules and not in main
		if len(err.Error()) > 30 && err.Error()[0:29] == "flag provided but not defined" {
			// requeue the parameter that failed
			modargs = append(modargs, err.Error()[31:])
		} else {
			// if it's another error, panic
			panic(err)
		}
	}
	for _, arg := range fs.Args() {
		modargs = append(modargs, arg)
	}
	modRunner = modules.Available[op.Module].Runner()
	if _, ok := modRunner.(modules.HasParamsParser); !ok {
		fmt.Fprintf(os.Stderr, "[error] module '%s' does not support command line invocation\n", op.Module)
		os.Exit(2)
	}
	op.Parameters, err = modRunner.(modules.HasParamsParser).ParamsParser(modargs)
	if err != nil || op.Parameters == nil {
		panic(err)
	}
	a.Operations = append(a.Operations, op)

	for _, arg := range os.Args[1:] {
		a.Name += arg + " "
	}
	a.Target = target

readytolaunch:
	// instanciate an API client
	conf, err = client.ReadConfiguration(migrc)
	if err != nil {
		panic(err)
	}
	cli, err = client.NewClient(conf, "cmd-"+version)
	if err != nil {
		panic(err)
	}

	// set the validity 60 second in the past to deal with clock skew
	a.ValidFrom = time.Now().Add(-60 * time.Second).UTC()
	period, err := time.ParseDuration(expiration)
	if err != nil {
		panic(err)
	}
	a.ExpireAfter = a.ValidFrom.Add(period)
	// add extra 60 seconds taken for clock skew
	a.ExpireAfter = a.ExpireAfter.Add(60 * time.Second).UTC()

	asig, err := cli.SignAction(a)
	if err != nil {
		panic(err)
	}
	a = asig

	// evaluate target before launch, give a change to cancel before going out to agents
	agents, err := cli.EvaluateAgentTarget(a.Target)
	if err != nil {
		panic(err)
	}
	fmt.Fprintf(os.Stderr, "\x1b[33m%d agents will be targeted. ctrl+c to cancel. launching in \x1b[0m", len(agents))
	for i := 5; i > 0; i-- {
		time.Sleep(1 * time.Second)
		fmt.Fprintf(os.Stderr, "\x1b[33m%d\x1b[0m ", i)
	}
	fmt.Fprintf(os.Stderr, "\x1b[33mGO\n\x1b[0m")

	// launch and follow
	a, err = cli.PostAction(a)
	if err != nil {
		panic(err)
	}
	c := make(chan os.Signal, 1)
	done := make(chan bool, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		err = cli.FollowAction(a)
		if err != nil {
			panic(err)
		}
		done <- true
	}()
	select {
	case <-c:
		fmt.Fprintf(os.Stderr, "stop following action. agents may still be running. printing available results:\n")
		goto printresults
	case <-done:
		goto printresults
	}
printresults:
	err = cli.PrintActionResults(a, show, render)
	if err != nil {
		panic(err)
	}
}
开发者ID:Novemburr,项目名称:mig,代码行数:101,代码来源:main.go


注:本文中的mig/client.Client.SignAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。