// docID is globalKey as written by someone who thought it would be
// helpful to reinvent the 'u#<unit>#' prefix (which *would* indicate
// that payloads are things-that-exist-per-unit, and do so in a way
// consistent with the rest of the DB. /sigh.)
18049
func (nsPayloads_) docID(unit, name string) string {
	return fmt.Sprintf("payload#%s#%s", unit, name)
}
785190
func resourceID(id, subType, subID string) string {
	if subType == "" {
		return fmt.Sprintf("resource#%s", id)
	}
	return fmt.Sprintf("resource#%s#%s-%s", id, subType, subID)
}
265561
func (i *BlockInfo) EntityId() EntityId {
	return EntityId{
		Kind:      "block",
		ModelUUID: i.ModelUUID,
		Id:        i.Id,
	}
}
167527
func (g *GPG) FormatKey(ctx context.Context, id string) string {
	return g.findKey(ctx, id).OneLine()
}
595107
func HDPrivateKeyToPublicKeyID(id []byte) ([]byte, error) {
	if len(id) != 4 {
		return nil, ErrUnknownHDKeyID
	}

	var key [4]byte
	copy(key[:], id)
	pubBytes, ok := hdPrivToPubKeyIDs[key]
	if !ok {
		return nil, ErrUnknownHDKeyID
	}

	return pubBytes, nil
}
141936
func (s *AbortDocumentVersionUploadInput) SetDocumentId(v string) *AbortDocumentVersionUploadInput {
	s.DocumentId = &v
	return s
}
497803
func UDID() string {
	f, err := os.Open("/dev/urandom")
	if err != nil {
		panic(fmt.Sprintf("failed to get /dev/urandom! %s", err))
	}
	b := make([]byte, 16)
	_, err = f.Read(b)
	if err != nil {
		panic(fmt.Sprintf("failed to read  16 bytes from /dev/urandom! %s", err))
	}
	f.Close()
	return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
}
507609
func (e *Endpoint) FormatGlobalEndpointID() string {
	localNodeName := node.GetName()
	metadata := []string{endpointid.CiliumGlobalIdPrefix.String(), ipcache.AddressSpace, localNodeName, strconv.Itoa(int(e.ID))}
	return strings.Join(metadata, ":")
}
92203
func PgAmprocByOid(db XODB, oid pgtypes.Oid) (*PgAmproc, error) {
	var err error

	// sql query
	const sqlstr = `SELECT ` +
		`tableoid, cmax, xmax, cmin, xmin, oid, ctid, amprocfamily, amproclefttype, amprocrighttype, amprocnum, amproc ` +
		`FROM pg_catalog.pg_amproc ` +
		`WHERE oid = $1`

	// run query
	XOLog(sqlstr, oid)
	pa := PgAmproc{}

	err = db.QueryRow(sqlstr, oid).Scan(&pa.Tableoid, &pa.Cmax, &pa.Xmax, &pa.Cmin, &pa.Xmin, &pa.Oid, &pa.Ctid, &pa.Amprocfamily, &pa.Amproclefttype, &pa.Amprocrighttype, &pa.Amprocnum, &pa.Amproc)
	if err != nil {
		return nil, err
	}

	return &pa, nil
}
436980
func printDocumentIds(documentPointers []*CouchDoc) (string, error) {

	documentIds := []string{}

	for _, documentPointer := range documentPointers {
		docMetadata := &DocMetadata{}
		err := json.Unmarshal(documentPointer.JSONValue, &docMetadata)
		if err != nil {
			return "", errors.Wrap(err, "error unmarshalling json data")
		}
		documentIds = append(documentIds, docMetadata.ID)
	}
	return strings.Join(documentIds, ","), nil
}
1232300
func (m *mapperDef) mapperID() mapper.ID {
	return mapper.ID(fmt.Sprintf("cipd:v1:%s", m.Kind))
}
463704
func keyID(raw interface{}) ([]byte, error) {
	switch raw.(type) {
	case *ecdsa.PublicKey:
	default:
		return nil, fmt.Errorf("invalid key type: %T", raw)
	}

	// This is not standard; RFC allows any unique identifier as long as they
	// match in subject/authority chains but suggests specific hashing of DER
	// bytes of public key including DER tags.
	bs, err := x509.MarshalPKIXPublicKey(raw)
	if err != nil {
		return nil, err
	}

	// String formatted
	kID := sha256.Sum256(bs)
	return []byte(strings.Replace(fmt.Sprintf("% x", kID), " ", ":", -1)), nil
}
959206
func (x *XC) FormatKey(ctx context.Context, id string) string {
	if key := x.pubring.Get(id); key != nil {
		return id + " - " + key.Identity.ID()
	}
	if key := x.secring.Get(id); key != nil {
		return id + " - " + key.PublicKey.Identity.ID()
	}
	return id
}
620545
func (md *RootMetadata) TlfID() tlf.ID {
	if md == nil || md.bareMd == nil {
		return tlf.NullID
	}
	return md.bareMd.TlfID()
}
471952
func (api CompaniesAPI) globalIdPut(w http.ResponseWriter, r *http.Request) {

	globalID := mux.Vars(r)["globalId"]

	var company companydb.Company

	if err := json.NewDecoder(r.Body).Decode(&company); err != nil {
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	companyMgr := companydb.NewCompanyManager(r)

	oldCompany, cerr := companyMgr.GetByName(globalID)
	if cerr != nil {
		log.Debug(cerr)
		http.Error(w, "Not found", http.StatusNotFound)
		return
	}

	if company.Globalid != globalID || company.GetId() != oldCompany.GetId() {
		http.Error(w, "Changing globalId or id is Forbidden!", http.StatusForbidden)
		return
	}

	if err := companyMgr.Save(&company); err != nil {
		log.Error("Error saving company:\n", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

}
256891
func (a *PGPGenArg) AddDefaultUID(g *GlobalContext) {
	a.Ids = append(a.Ids, KeybaseIdentity(g, ""))
}
511040
func backingEntityIdForGlobalKey(modelUUID, key string) (multiwatcher.EntityId, bool) {
	if key == modelGlobalKey {
		return (&multiwatcher.ModelInfo{
			ModelUUID: modelUUID,
		}).EntityId(), true
	} else if len(key) < 3 || key[1] != '#' {
		return multiwatcher.EntityId{}, false
	}
	id := key[2:]
	switch key[0] {
	case 'm':
		id = strings.TrimSuffix(id, "#instance")
		return (&multiwatcher.MachineInfo{
			ModelUUID: modelUUID,
			Id:        id,
		}).EntityId(), true
	case 'u':
		id = strings.TrimSuffix(id, "#charm")
		return (&multiwatcher.UnitInfo{
			ModelUUID: modelUUID,
			Name:      id,
		}).EntityId(), true
	case 'a':
		return (&multiwatcher.ApplicationInfo{
			ModelUUID: modelUUID,
			Name:      id,
		}).EntityId(), true
	case 'c':
		return (&multiwatcher.RemoteApplicationInfo{
			ModelUUID: modelUUID,
			Name:      id,
		}).EntityId(), true
	default:
		return multiwatcher.EntityId{}, false
	}
}