// SaveRecipients persists the current recipients on disk
495727
func (s *Store) SaveRecipients(ctx context.Context) error {
	rs, err := s.GetRecipients(ctx, "")
	if err != nil {
		return errors.Wrapf(err, "failed to get recipients")
	}
	return s.saveRecipients(ctx, rs, "Save Recipients", true)
}
1183359
func (s *Store) saveRecipients(ctx context.Context, rs []string, msg string, exportKeys bool) error {
	if len(rs) < 1 {
		return errors.New("can not remove all recipients")
	}

	idf := s.idFile(ctx, "")
	buf := marshalRecipients(rs)
	if err := s.storage.Set(ctx, idf, buf); err != nil {
		return errors.Wrapf(err, "failed to write recipients file")
	}

	if err := s.sc.SetRecipientHash(s.alias, idf, sha3fp(buf)); err != nil {
		return errors.Wrapf(err, "failed to update recipients hash")
	}

	if err := s.rcs.Add(ctx, idf); err != nil {
		if err != store.ErrGitNotInit {
			return errors.Wrapf(err, "failed to add file '%s' to git", idf)
		}
	}

	if err := s.rcs.Commit(ctx, msg); err != nil {
		if err != store.ErrGitNotInit && err != store.ErrGitNothingToCommit {
			return errors.Wrapf(err, "failed to commit changes to git")
		}
	}

	// save all recipients public keys to the repo
	if exportKeys {
		if _, err := s.ExportMissingPublicKeys(ctx, rs); err != nil {
			out.Error(ctx, "Failed to export missing public keys: %s", err)
		}
	}

	// return if autosync is not enabled
	if !IsAutoSync(ctx) {
		return nil
	}

	// push to remote repo
	if err := s.rcs.Push(ctx, "", ""); err != nil {
		if errors.Cause(err) == store.ErrGitNotInit {
			return nil
		}
		if errors.Cause(err) == store.ErrGitNoRemote {
			msg := "Warning: git has no remote. Ignoring auto-push option\n" +
				"Run: gopass git remote add origin ..."
			out.Yellow(ctx, msg)
			return nil
		}
		return errors.Wrapf(err, "failed to push changes to git")
	}

	return nil
}
212539
func (s *RecipientDsnFields) SetFinalRecipient(v string) *RecipientDsnFields {
	s.FinalRecipient = &v
	return s
}
658227
func (g *GPG) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) {
	recps := make([]string, 0, 1)
	packets := packet.NewReader(bytes.NewReader(ciphertext))
	for {
		p, err := packets.Next()
		if err != nil {
			if err == io.EOF {
				break
			}
			return nil, err
		}
		switch p := p.(type) {
		case *packet.EncryptedKey:
			for _, key := range g.pubring {
				if key.PrimaryKey == nil {
					continue
				}
				if key.PrimaryKey.KeyId == p.KeyId {
					recps = append(recps, key.PrimaryKey.KeyIdString())
				}
			}
		}
	}
	return recps, nil
}
600704
func (p *Pushover) GetRecipientDetails(recipient *Recipient) (*RecipientDetails, error) {
	endpoint := fmt.Sprintf("%s/users/validate.json", APIEndpoint)

	// Validate pushover
	if err := p.validate(); err != nil {
		return nil, err
	}

	// Validate recipient
	if err := recipient.validate(); err != nil {
		return nil, err
	}

	req, err := newURLEncodedRequest("POST", endpoint,
		map[string]string{"token": p.token, "user": recipient.token})
	if err != nil {
		return nil, err
	}

	var response RecipientDetails
	if err := do(req, &response, false); err != nil {
		return nil, err
	}

	return &response, nil
}
18952
func SaveUser(host, token, id string, doc map[string]interface{}) (*map[string]interface{}, error) {
	path := variables.APIPathUser
	path = strings.Replace(path, ":id", id, 1)
	doc["_id"] = id
	return GenericRequest(host, path, token, doc)
}
190933
func (api *RemoteRelationsAPI) SaveMacaroons(args params.EntityMacaroonArgs) (params.ErrorResults, error) {
	results := params.ErrorResults{
		Results: make([]params.ErrorResult, len(args.Args)),
	}
	for i, arg := range args.Args {
		entityTag, err := names.ParseTag(arg.Tag)
		if err != nil {
			results.Results[i].Error = common.ServerError(err)
			continue
		}
		err = api.st.SaveMacaroon(entityTag, arg.Macaroon)
		results.Results[i].Error = common.ServerError(err)
	}
	return results, nil
}
925093
func GetRecipientFunc(ctx context.Context) store.RecipientCallback {
	imf, ok := ctx.Value(ctxKeyRecipientFunc).(store.RecipientCallback)
	if !ok || imf == nil {
		return func(ctx context.Context, msg string, rs []string) ([]string, error) {
			return rs, nil
		}
	}
	return imf
}
1235156
func (ic *InboundCall) WriteToResponse(resw transport.ResponseWriter) error {
	var headers transport.Headers
	for _, h := range ic.resHeaders {
		headers = headers.With(h.k, h.v)
	}

	if headers.Len() > 0 {
		resw.AddHeaders(headers)
	}

	return nil
}
1276333
func (s *BouncedRecipientInfo) SetRecipientArn(v string) *BouncedRecipientInfo {
	s.RecipientArn = &v
	return s
}
569280
func (i *InstallReceipt) Save(w io.Writer) error {
	data, err := json.MarshalIndent(i, "", "  ")
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	w.Write([]byte("\n"))
	return err
}
205685
func (s *Server) readRecipients(c *Connection) {
	text := c.read()
	s.addMessageLine(text)

	c.write("250 Recipient")
	text = c.read()
	for strings.Contains(text, "RCPT") {
		s.addMessageLine(text)
		c.write("250 Recipient")
		text = c.read()
	}
}
708924
func LookupRecipient(m libkb.MetaContext, to stellarcommon.RecipientInput, isCLI bool) (res stellarcommon.Recipient, err error) {
	defer m.TraceTimed("Stellar.LookupRecipient", func() error { return err })()

	res = stellarcommon.Recipient{
		Input: to,
	}
	if len(to) == 0 {
		return res, fmt.Errorf("empty recipient parameter")
	}

	storeAddress := func(address string) error {
		_, err := libkb.ParseStellarAccountID(address)
		if err != nil {
			if verr, ok := err.(libkb.VerboseError); ok {
				m.Debug(verr.Verbose())
			}
			return err
		}
		accountID, err := stellarnet.NewAddressStr(address)
		if err != nil {
			return err
		}
		res.AccountID = &accountID
		return nil
	}

	// Federation address
	if strings.Contains(string(to), stellarAddress.Separator) {
		name, domain, err := stellarAddress.Split(string(to))
		if err != nil {
			return res, err
		}

		if domain == "keybase.io" {
			// Keybase.io federation address. Fall through to identify
			// path.
			m.Debug("Got federation address %q but it's under keybase.io domain!", to)
			m.Debug("Instead going to lookup Keybase assertion: %q", name)
			to = stellarcommon.RecipientInput(name)
		} else {
			// Actual federation address that is not under keybase.io
			// domain. Use federation client.
			fedCli := getGlobal(m.G()).federationClient
			nameResponse, err := fedCli.LookupByAddress(string(to))
			if err != nil {
				errStr := err.Error()
				m.Debug("federation.LookupByAddress returned error: %s", errStr)
				if strings.Contains(errStr, "lookup federation server failed") {
					return res, fmt.Errorf("Server at url %q does not respond to federation requests", domain)
				} else if strings.Contains(errStr, "get federation failed") {
					return res, fmt.Errorf("Federation server %q did not find record %q", domain, name)
				}
				return res, err
			}
			// We got an address! Fall through to the "Stellar
			// address" path.
			m.Debug("federation.LookupByAddress returned: %+v", nameResponse)
			to = stellarcommon.RecipientInput(nameResponse.AccountID)
		}
	}

	// Stellar account ID
	if to[0] == 'G' && len(to) > 16 {
		err := storeAddress(string(to))
		return res, err
	}

	maybeUsername, err := lookupRecipientAssertion(m, string(to), isCLI)
	if err != nil {
		return res, err
	}
	if maybeUsername == "" {
		expr, err := externals.AssertionParse(m.G(), string(to))
		if err != nil {
			m.Debug("error parsing assertion: %s", err)
			return res, fmt.Errorf("invalid recipient %q: %s", to, err)
		}

		// valid assertion, but not a user yet
		m.Debug("assertion %s (%s) is valid, but not a user yet", to, expr)
		social, err := expr.ToSocialAssertion()
		if err != nil {
			m.Debug("not a social assertion: %s (%s)", to, expr)
			if _, ok := expr.(libkb.AssertionKeybase); ok {
				return res, libkb.NotFoundError{Msg: fmt.Sprintf("user not found: %q", to)}
			}
			return res, fmt.Errorf("invalid recipient %q: %s", to, err)
		}
		res.Assertion = &social
		return res, nil
	}

	// load the user to get their wallet
	user, err := libkb.LoadUser(
		libkb.NewLoadUserByNameArg(m.G(), maybeUsername).
			WithNetContext(m.Ctx()).
			WithPublicKeyOptional())
	if err != nil {
		return res, err
	}
	res.User = &stellarcommon.User{
		UV:       user.ToUserVersion(),
		Username: user.GetNormalizedName(),
	}
	accountID := user.StellarAccountID()
	if accountID == nil {
		return res, nil
	}
	err = storeAddress(accountID.String())
	return res, err
}
160212
func (r *Store) ListRecipients(ctx context.Context, store string) []string {
	ctx, sub, _ := r.getStore(ctx, store)
	return sub.Recipients(ctx)
}
100582
func (c *Config) GetRecipientHash(alias, name string) string {
	if alias == "" {
		return c.Root.RecipientHash[name]
	}
	if sc, found := c.Mounts[alias]; found && sc != nil {
		return sc.RecipientHash[name]
	}
	return ""
}
838840
func ConfirmRecipients(ctx context.Context, crypto backend.Crypto, name string, recipients []string) ([]string, error) {
	if ctxutil.IsNoConfirm(ctx) || !ctxutil.IsInteractive(ctx) {
		return recipients, nil
	}

	ris, err := getRecipientInfo(ctx, crypto, name, recipients)
	if err != nil {
		return nil, err
	}

	if ctxutil.IsEditRecipients(ctx) {
		return confirmEditRecipients(ctx, name, ris)
	}

	return confirmAskRecipients(ctx, name, ris)
}
238608
func (we *WorkflowExecutor) SaveArtifacts() error {
	if len(we.Template.Outputs.Artifacts) == 0 {
		log.Infof("No output artifacts")
		return nil
	}
	log.Infof("Saving output artifacts")
	mainCtrID, err := we.GetMainContainerID()
	if err != nil {
		return err
	}

	err = os.MkdirAll(tempOutArtDir, os.ModePerm)
	if err != nil {
		return errors.InternalWrapError(err)
	}

	for i, art := range we.Template.Outputs.Artifacts {
		err := we.saveArtifact(mainCtrID, &art)
		if err != nil {
			return err
		}
		we.Template.Outputs.Artifacts[i] = art
	}
	return nil
}