// Actions returns the Actions by Tags passed and ensures that the machine asking
// for them is the machine that has the actions
761285
func (f *Facade) Actions(args params.Entities) params.ActionResults {
	actionFn := common.AuthAndActionFromTagFn(f.accessMachine, f.backend.ActionByTag)
	return common.Actions(args, actionFn)
}
128490
func (c *Change) Action() (merkletrie.Action, error) {
	if c.From == empty && c.To == empty {
		return merkletrie.Action(0),
			fmt.Errorf("malformed change: empty from and to")
	}
	if c.From == empty {
		return merkletrie.Insert, nil
	}
	if c.To == empty {
		return merkletrie.Delete, nil
	}

	return merkletrie.Modify, nil
}
435229
func (mod *TumblrBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "post_text":
		text := ""
		action.Options.Bind("text", &text)

		state := "published"
		err := mod.client.CreateText(mod.blogname, map[string]string{
			"body":  text,
			"state": state})
		if err != nil {
			mod.LogErrorf("Failed to post text: %v", err)
			return outs
		}
		ev := bees.Event{
			Bee:     mod.Name(),
			Name:    "posted",
			Options: []bees.Placeholder{},
		}
		mod.evchan <- ev

	case "post_quote":
		quote := ""
		source := ""
		action.Options.Bind("quote", &quote)
		action.Options.Bind("source", &source)

		state := "published"
		err := mod.client.CreateQuote(mod.blogname, map[string]string{
			"quote":  quote,
			"source": source,
			"state":  state})
		if err != nil {
			mod.LogErrorf("Failed to post quote: %v", err)
			return outs
		}
		ev := bees.Event{
			Bee:     mod.Name(),
			Name:    "posted",
			Options: []bees.Placeholder{},
		}
		mod.evchan <- ev

	case "follow":
		blogname := ""
		action.Options.Bind("blogname", &blogname)

		if err := mod.client.Follow(blogname); err != nil {
			mod.LogErrorf("Failed to follow blog: %v", err)
			return outs
		}

	case "unfollow":
		blogname := ""
		action.Options.Bind("blogname", &blogname)

		if err := mod.client.Unfollow(blogname); err != nil {
			mod.LogErrorf("Failed to unfollow blog: %v", err)
			return outs
		}

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
293578
func (a *Application) Action(action Action) *Application {
	a.addAction(action)
	return a
}
244257
func (client *AMIClient) Action(action string, params Params) (*AMIResponse, error) {
	resp, err := client.AsyncAction(action, params)
	if err != nil {
		return nil, err
	}
	response := <-resp

	return response, nil
}
401424
func (kf *UITestFixer) Action(ctx context.Context, name string) error {
	if name == "Success" {
		return nil
	}
	if name == "Error" {
		return fmt.Errorf("oh no, you pressed the Error button")
	}
	return fmt.Errorf("unknown UITestFixer action: %v", name)
}
2391
func Action(a func(*cli.Context)) Option {
	return func(o *Options) {
		o.Action = a
	}
}
847013
func (st *State) Machines(tags ...names.MachineTag) ([]MachineResult, error) {
	lenTags := len(tags)
	genericTags := make([]names.Tag, lenTags)
	for i, t := range tags {
		genericTags[i] = t
	}
	result, err := common.Life(st.facade, genericTags)
	if err != nil {
		return []MachineResult{}, err
	}
	machines := make([]MachineResult, lenTags)
	for i, r := range result {
		if r.Error == nil {
			machines[i].Machine = &Machine{
				tag:  tags[i],
				life: r.Life,
				st:   st,
			}
		} else {
			machines[i].Err = r.Error
		}
	}
	return machines, nil
}
693431
func (l *List) GetActions(args Arguments) (actions ActionCollection, err error) {
	path := fmt.Sprintf("lists/%s/actions", l.ID)
	err = l.client.Get(path, args, &actions)
	return
}
968260
func (mod *SimplepushBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "send":
		sm := simplepush.Message{
			SimplePushKey: mod.key,
			Encrypt:       mod.password != "",
			Password:      mod.password,
			Salt:          mod.salt,
		}
		action.Options.Bind("title", &sm.Title)
		action.Options.Bind("message", &sm.Message)
		action.Options.Bind("event", &sm.Event)

		simplepush.Send(sm)

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
738312
func (f *Facade) RunningActions(args params.Entities) params.ActionsByReceivers {
	canAccess := f.accessMachine
	tagToActionReceiver := f.backend.TagToActionReceiverFn(f.backend.FindEntity)

	response := params.ActionsByReceivers{
		Actions: make([]params.ActionsByReceiver, len(args.Entities)),
	}

	for i, entity := range args.Entities {
		currentResult := &response.Actions[i]
		receiver, err := tagToActionReceiver(entity.Tag)
		if err != nil {
			currentResult.Error = common.ServerError(common.ErrBadId)
			continue
		}
		currentResult.Receiver = receiver.Tag().String()

		if !canAccess(receiver.Tag()) {
			currentResult.Error = common.ServerError(common.ErrPerm)
			continue
		}

		results, err := f.backend.ConvertActions(receiver, receiver.RunningActions)
		if err != nil {
			currentResult.Error = common.ServerError(err)
			continue
		}
		currentResult.Actions = results
	}

	return response
}
1012730
func (writer *SocketWriter) Tags() map[string]string {
	writer.lock.RLock()
	defer writer.lock.RUnlock()
	return writer.tags
}
964850
func (s *TasksCancelService) Actions(actions ...string) *TasksCancelService {
	s.actions = append(s.actions, actions...)
	return s
}
257910
func (mod *SpaceAPIBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "status":
		type SpaceAPIResult struct {
			State struct {
				Open bool `json:"open"`
			} `json:"state"`
		}
		apiState := new(SpaceAPIResult)

		// get json data
		resp, err := http.Get(mod.url)
		if err != nil {
			mod.Logln("Error: SpaceAPI instance @ " + mod.url + " not reachable")
		} else {
			defer resp.Body.Close()
			body, _ := ioutil.ReadAll(resp.Body)

			err = json.Unmarshal(body, apiState)
			if err != nil {
				mod.Logln("Sorry, couldn't unmarshal the JSON data from SpaceAPI Instance @ " + mod.url)
				apiState.State.Open = false
			}
		}

		ev := bees.Event{
			Bee:  mod.Name(),
			Name: "result",
			Options: []bees.Placeholder{
				{
					Name:  "open",
					Type:  "bool",
					Value: apiState.State.Open,
				},
			},
		}
		mod.evchan <- ev

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
210081
func (r *PURuntime) Tags() *TagStore {
	r.Lock()
	defer r.Unlock()

	return r.tags.Copy()
}
1211545
func (mod *ExecBee) Action(action bees.Action) []bees.Placeholder {
	outs := []bees.Placeholder{}

	switch action.Name {
	case "execute":
		var command string
		var stdin string

		action.Options.Bind("command", &command)
		action.Options.Bind("stdin", &stdin)
		mod.Logln("Executing locally: ", command)

		go func() {
			c := strings.Split(command, " ")
			cmd := exec.Command(c[0], c[1:]...)

			if stdin != "" {
				stdinPipe, err := cmd.StdinPipe()

				if err != nil {
					mod.LogFatal("Error creating stdinPipe for Cmd", err)
					return
				}

				go func() {
					io.WriteString(stdinPipe, stdin)
					stdinPipe.Close()
				}()
			}

			// read and print stdout
			outReader, err := cmd.StdoutPipe()
			if err != nil {
				mod.LogFatal("Error creating StdoutPipe for Cmd", err)
				return
			}
			outBuffer := []string{}
			outScanner := bufio.NewScanner(outReader)
			go func() {
				for outScanner.Scan() {
					foo := outScanner.Text()
					mod.Logln("execbee: std: | ", foo)
					outBuffer = append(outBuffer, foo)
				}
			}()

			// read and print stderr
			errReader, err := cmd.StderrPipe()
			if err != nil {
				mod.LogFatal("Error creating StderrPipe for Cmd", err)
				return
			}
			errBuffer := []string{}
			errScanner := bufio.NewScanner(errReader)
			go func() {
				for errScanner.Scan() {
					foo := errScanner.Text()
					mod.Logln("Err: | ", foo)
					errBuffer = append(errBuffer, foo)
				}
			}()

			err = cmd.Start()
			if err != nil {
				mod.LogFatal("Error starting Cmd", err)
			}

			err = cmd.Wait()
			if err != nil {
				mod.LogFatal("Error waiting for Cmd", err)
			}

			ev := bees.Event{
				Bee:  mod.Name(),
				Name: "result",
				Options: []bees.Placeholder{
					{
						Name:  "stdout",
						Type:  "string",
						Value: strings.Join(outBuffer, "\n"),
					},
					{
						Name:  "stderr",
						Type:  "string",
						Value: strings.Join(errBuffer, "\n"),
					},
				},
			}
			mod.eventChan <- ev
		}()

	default:
		panic("Unknown action triggered in " + mod.Name() + ": " + action.Name)
	}

	return outs
}
1035741
func getActionTagsByPrefix(api APIClient, prefix string) ([]names.ActionTag, error) {
	results := []names.ActionTag{}

	tags, err := api.FindActionTagsByPrefix(params.FindTags{Prefixes: []string{prefix}})
	if err != nil {
		return results, err
	}

	matches, ok := tags.Matches[prefix]
	if !ok || len(matches) < 1 {
		return results, nil
	}

	results, rejects := getActionTags(matches)
	if len(rejects) > 0 {
		logger.Errorf("FindActionTagsByPrefix for prefix %q found invalid tags %v", prefix, rejects)
	}
	return results, nil
}