Beispiel #1
0
func (s *RemoteServer) RunPlugin(ctx context.Context, step *plan.WorkflowStep) (*report.Report, error) {
	// create session inside current session
	child := &scan.Session{
		Scan:   s.sess.Scan,
		Parent: s.sess.Id,
		Step:   step,
	}
	sess, err := s.api.Scans.SessionAddChild(ctx, child)
	if err != nil {
		return nil, err
	}
	// wait for session status finished
loop:
	for {
		select {
		case <-ctx.Done():
			return nil, ctx.Err()
		default:
		}
		sess2, err := s.api.Scans.SessionGet(ctx, client.FromId(sess.Scan), client.FromId(sess.Id))
		if err != nil {
			if client.IsNotFound(err) {
				// why session is not found???
				return nil, err
			}
			logrus.Error(err)
			// TODO (m0sth8): add errors counter and fail if counter is more then maximum
			// TODO (m0sth8): add exponential sleep on errors
			time.Sleep(time.Second * 15)
			continue loop
		}
		switch sess2.Status {
		case scan.StatusFinished:
			break loop
		case scan.StatusFailed:
			return nil, fmt.Errorf("session was failed")
		case scan.StatusPaused:
			time.Sleep(time.Second * 30)
			continue loop
		}
		time.Sleep(time.Second * 2)
	}

	rep, err := s.api.Scans.SessionReportGet(ctx, sess)
	if err != nil {
		return nil, err
	}
	return rep, nil
}
Beispiel #2
0
func plansShowAction(ctx *cli.Context, api *client.Client, timeout Timeout) {
	if len(ctx.Args()) == 0 {
		fmt.Printf("You should set plan id argument: plans show [id]\n")
		os.Exit(1)
	}
	plan, err := api.Plans.Get(timeout(), ctx.Args()[0])
	if err != nil {
		if client.IsNotFound(err) {
			fmt.Println("Plan not found")
			return
		}
		fmt.Print(err)
		return
	}
	fmt.Println("Plan found:")
	data, err := json.MarshalIndent(plan, "", "    ")
	if err != nil {
		panic(err)
	}
	fmt.Println(string(data))
	return
}