// Read state from key.
163416
func (d *EtcdStateDriver) Read(key string) ([]byte, error) {
	ctx, cancel := context.WithTimeout(context.Background(), ctxTimeout)
	defer cancel()

	var err error
	var resp *client.Response

	for i := 0; i < maxEtcdRetries; i++ {
		resp, err = d.KeysAPI.Get(ctx, key, &client.GetOptions{Quorum: true})
		if err == nil {
			if resp != nil && resp.Node != nil {
				return []byte(resp.Node.Value), nil
			}

			return []byte{}, fmt.Errorf("error reading from etcd")
		}

		if client.IsKeyNotFound(err) {
			return []byte{}, core.Errorf("key not found")
		}

		if err.Error() == client.ErrClusterUnavailable.Error() {
			// Retry after a delay
			time.Sleep(time.Second)
			continue
		}

		return []byte{}, err
	}

	return []byte{}, err
}
706366
func (f *FileStore) Read(key []byte, t int64) ([]Value, error) {
	f.mu.RLock()
	defer f.mu.RUnlock()

	for _, f := range f.files {
		// Can this file possibly contain this key and timestamp?
		if !f.Contains(key) {
			continue
		}

		// May have the key and time we are looking for so try to find
		v, err := f.Read(key, t)
		if err != nil {
			return nil, err
		}

		if len(v) > 0 {
			return v, nil
		}
	}
	return nil, nil
}
1220827
func (s *CfgPolicyRule) Read(id string) error {
	key := fmt.Sprintf(policyRuleConfigPath, id)
	return s.StateDriver.ReadState(key, s, json.Unmarshal)
}
1172537
func (s *OvsDriverOperState) Read(id string) error {
	key := fmt.Sprintf(ovsOperPath, id)
	return s.StateDriver.ReadState(key, s, json.Unmarshal)
}
1038942
func (q *lockBasedQueryExecutor) GetState(ns string, key string) (val []byte, err error) {
	val, _, err = q.helper.getState(ns, key)
	return
}
314074
func (r *AutoVLANCfgResource) Read(id string) error {
	key := fmt.Sprintf(vLANResourceConfigPath, id)
	return r.StateDriver.ReadState(key, r, json.Unmarshal)
}
743177
func (s *SvcProvider) Read(id string) error {
	key := fmt.Sprintf(svcProviderPath, id)
	err := s.StateDriver.ReadState(key, s, json.Unmarshal)
	return err
}
751707
func (gp *EpgPolicy) Read(id string) error {
	key := fmt.Sprintf(policyConfigPath, id)
	return gp.StateDriver.ReadState(key, gp, json.Unmarshal)
}
735088
func (d *state) Read(out []byte) (n int, err error) {
	// If we're still absorbing, pad and apply the permutation.
	if d.state == spongeAbsorbing {
		d.padAndPermute(d.dsbyte)
	}

	n = len(out)

	// Now, do the squeezing.
	for len(out) > 0 {
		n := copy(out, d.buf)
		d.buf = d.buf[n:]
		out = out[n:]

		// Apply the permutation if we've squeezed the sponge dry.
		if len(d.buf) == 0 {
			d.permute()
		}
	}

	return
}
224546
func (g *Oper) ReadAll() ([]core.State, error) {
	return g.StateDriver.ReadAllState(operGlobalPrefix, g, json.Unmarshal)
}
415431
func readKeyMap(r *bufio.Reader) (key string, msg map[string]interface{}, err error) {
	key, err = readString1(r)
	if err != nil {
		return
	}
	msg, err = readMap(r, false)
	return
}
730817
func (s *CfgServiceLBState) Read(id string) error {
	key := fmt.Sprintf(serviceLBConfigPath, id)
	err := s.StateDriver.ReadState(key, s, json.Unmarshal)
	return err
}
548200
func Read(secustom string) (config string, err error) {
	// This is the default encoded-but-not-safe blank password

	naclKey := new([keySize]byte)
	copy(naclKey[:], pad[:keySize])
	nonce := new([nonceSize]byte)
	in, err := ioutil.ReadFile(returnHome() + "/." + secustom)
	if err != nil {
		return "", err
	}
	copy(nonce[:], in[:nonceSize])
	configbytes, ok := secretbox.Open(nil, in[nonceSize:], nonce, naclKey)
	if ok {
		return string(configbytes), nil
	}

	// The blank password didn't work. Ask the user via speakeasy
	userKey, err := speakeasy.Ask("Password: ")

	key := []byte(userKey)
	key = append(key, pad...)
	naclKey = new([keySize]byte)
	copy(naclKey[:], key[:keySize])
	nonce = new([nonceSize]byte)
	in, err = ioutil.ReadFile(returnHome() + "/." + secustom)
	if err != nil {
		return "", err
	}
	copy(nonce[:], in[:nonceSize])
	configbytes, ok = secretbox.Open(nil, in[nonceSize:], nonce, naclKey)
	if !ok {
		return "", errors.New("Could not decrypt the config file. Wrong password?")
	}

	return string(configbytes), nil

}
605101
func InitState(key string, value interface{}) Option {
	return func(p *parser) Option {
		old := p.cur.state[key]
		p.cur.state[key] = value
		return InitState(key, old)
	}
}
803269
func (rs *resourceState) Key() string {
	return fmt.Sprintf("%s/%s/%s/%s", rs.Group, rs.Kind, rs.Namespace, rs.Name)
}
1025324
func (r *AutoVXLANCfgResource) Read(id string) error {
	key := fmt.Sprintf(vXLANResourceConfigPath, id)
	return r.StateDriver.ReadState(key, r, json.Unmarshal)
}
317042
func (api *ServerAPI) State(id int64) (string, error) {
	server, err := api.Read(id)
	if err != nil {
		return "", err
	}
	return string(server.Availability), nil
}