// NewEnquireLinkResp creates and initializes a EnquireLinkResp PDU.
167921
func NewEnquireLinkResp() Body {
	b := newEnquireLinkResp(&Header{ID: EnquireLinkRespID})
	b.init()
	return b
}
516895
func newPagingLinks(basePath string, opts platform.FindOptions, f platform.PagingFilter, num int) *platform.PagingLinks {
	u := url.URL{
		Path: basePath,
	}

	values := url.Values{}
	for k, vs := range f.QueryParams() {
		for _, v := range vs {
			if v != "" {
				values.Add(k, v)
			}
		}
	}

	var self, next, prev string
	for k, vs := range opts.QueryParams() {
		for _, v := range vs {
			if v != "" {
				values.Add(k, v)
			}
		}
	}

	u.RawQuery = values.Encode()
	self = u.String()

	if num >= opts.Limit {
		nextOffset := opts.Offset + opts.Limit
		values.Set("offset", strconv.Itoa(nextOffset))
		u.RawQuery = values.Encode()
		next = u.String()
	}

	if opts.Offset > 0 {
		prevOffset := opts.Offset - opts.Limit
		if prevOffset < 0 {
			prevOffset = 0
		}
		values.Set("offset", strconv.Itoa(prevOffset))
		u.RawQuery = values.Encode()
		prev = u.String()
	}

	links := &platform.PagingLinks{
		Prev: prev,
		Self: self,
		Next: next,
	}

	return links
}
285784
func NewFileSink(conf *sink.SinkConfig) (sink.Sink, error) {
	if conf.Logger == nil {
		return nil, errors.New("nil logger provided")
	}

	conf.Logger.Info("creating file sink")

	f := &fileSink{
		logger: conf.Logger,
	}

	pathRaw, ok := conf.Config["path"]
	if !ok {
		return nil, errors.New("'path' not specified for file sink")
	}
	path, ok := pathRaw.(string)
	if !ok {
		return nil, errors.New("could not parse 'path' as string")
	}

	f.path = path

	if err := f.WriteToken(""); err != nil {
		return nil, errwrap.Wrapf("error during write check: {{err}}", err)
	}

	f.logger.Info("file sink configured", "path", f.path)

	return f, nil
}
627850
func (m *MockRPCClient) NewRPCClient(contextID, channel, rpcSecret string) error {
	ret := m.ctrl.Call(m, "NewRPCClient", contextID, channel, rpcSecret)
	ret0, _ := ret[0].(error)
	return ret0
}
222998
func (s *Service) NewPTR(name string, target string) *dns.PTR {
	return &dns.PTR{Hdr: dns.RR_Header{Name: name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: s.TTL}, Ptr: dns.Fqdn(target)}
}
1164398
func RenameRepo(
	ctx context.Context, config libkbfs.Config, tlfHandle *tlfhandle.Handle,
	oldRepoName, newRepoName string) (err error) {
	if !checkValidRepoName(newRepoName, config) {
		return errors.WithStack(libkb.InvalidRepoNameError{Name: newRepoName})
	}

	kbfsOps := config.KBFSOps()
	rootNode, _, err := kbfsOps.GetOrCreateRootNode(
		ctx, tlfHandle, data.MasterBranch)
	if err != nil {
		return err
	}
	normalizedOldRepoName := normalizeRepoName(oldRepoName)
	normalizedNewRepoName := normalizeRepoName(newRepoName)

	repoNode, _, err := kbfsOps.Lookup(ctx, rootNode, kbfsRepoDir)
	if err != nil {
		return err
	}

	// Does the old repo definitely exist?
	_, _, err = kbfsOps.Lookup(ctx, repoNode, normalizedOldRepoName)
	if err != nil {
		return err
	}

	if oldRepoName == newRepoName {
		// The names are the same, nothing else to do.
		return nil
	}

	fs, err := libfs.NewFS(
		ctx, config, tlfHandle, data.MasterBranch, path.Join(kbfsRepoDir),
		"", keybase1.MDPriorityGit)
	if err != nil {
		return err
	}

	oldRepoFS, err := fs.Chroot(normalizedOldRepoName)
	if err != nil {
		return err
	}

	// Take locks in both repos during rename (same lock that's taken
	// for new repo creation).
	oldLockFile, err := takeConfigLock(
		oldRepoFS.(*libfs.FS), tlfHandle, oldRepoName)
	if err != nil {
		return err
	}
	defer func() {
		closeErr := oldLockFile.Close()
		if err == nil {
			err = closeErr
		}
	}()

	if normalizedOldRepoName == normalizedNewRepoName {
		// All we need to do is update the name in the config file,
		// and the MD.
		err = renameRepoInConfigFile(ctx, oldRepoFS, newRepoName)
		if err != nil {
			return err
		}
		// We pass in `oldRepoFS`, which now has the new repo name in its
		// config.
		return UpdateRepoMD(ctx, config, tlfHandle, oldRepoFS,
			keybase1.GitPushType_RENAMEREPO, oldRepoName, nil)
	}

	// Does the new repo not exist yet?
	_, ei, err := kbfsOps.Lookup(ctx, repoNode, normalizedNewRepoName)
	switch errors.Cause(err).(type) {
	case idutil.NoSuchNameError:
		// The happy path.
	case nil:
		if ei.Type == data.Sym {
			config.MakeLogger("").CDebugf(
				ctx, "Overwriting symlink for repo %s with a new repo",
				normalizedNewRepoName)
			err = config.KBFSOps().RemoveEntry(
				ctx, repoNode, normalizedNewRepoName)
			if err != nil {
				return err
			}
		} else {
			newRepoFS, err := fs.Chroot(normalizedNewRepoName)
			if err != nil {
				return err
			}
			// Someone else already created and initialized the repo.
			return makeExistingRepoError(ctx, config, newRepoFS, newRepoName)
		}
	default:
		return err
	}

	// Make the new repo subdir just so we can take the lock inside
	// the new repo.  (We'll delete the new dir before the rename.)
	err = fs.MkdirAll(normalizedNewRepoName, 0777)
	if err != nil {
		return err
	}
	newRepoFS, err := fs.Chroot(normalizedNewRepoName)
	if err != nil {
		return err
	}
	newLockFile, err := takeConfigLock(
		newRepoFS.(*libfs.FS), tlfHandle, newRepoName)
	if err != nil {
		return err
	}
	defer func() {
		closeErr := newLockFile.Close()
		if err == nil {
			err = closeErr
		}
	}()

	// Rename this new dir out of the way before we rename.
	fi, err := fs.Stat(normalizedNewRepoName)
	if err != nil {
		return err
	}
	err = libfs.RecursiveDelete(ctx, fs, fi)
	if err != nil {
		return err
	}

	// Now update the old config file and rename, and leave a symlink
	// behind.  TODO: if any of the modifying steps below fail, we
	// should technically clean up any modifications before return, so
	// they don't get flushed.  However, with journaling on these are
	// all local operations and all very unlikely to fail.
	err = renameRepoInConfigFile(ctx, oldRepoFS, newRepoName)
	if err != nil {
		return err
	}
	err = fs.Rename(normalizedOldRepoName, normalizedNewRepoName)
	if err != nil {
		return err
	}
	err = fs.Symlink(normalizedNewRepoName, normalizedOldRepoName)
	if err != nil {
		return err
	}
	newRepoFS, err = fs.Chroot(normalizedNewRepoName)
	if err != nil {
		return err
	}
	return UpdateRepoMD(ctx, config, tlfHandle, newRepoFS,
		keybase1.GitPushType_RENAMEREPO, oldRepoName, nil)
}
257130
func (c *Client) NewLunMap(opts *NewLunMapOptions) (NewLunMapResult, error) {
	req := xms.PostLunMapsReq(*opts)
	return c.api.PostLunMaps(&req)
}
985699
func NewInmemSink(interval, retain time.Duration) *InmemSink {
	rateTimeUnit := time.Second
	i := &InmemSink{
		interval:     interval,
		retain:       retain,
		maxIntervals: int(retain / interval),
		rateDenom:    float64(interval.Nanoseconds()) / float64(rateTimeUnit.Nanoseconds()),
	}
	i.intervals = make([]*IntervalMetrics, 0, i.maxIntervals)
	return i
}
367179
func (s *MyNewRelic) New(appEnv *cfenv.App) *MyNewRelic {
	serviceName := os.Getenv("NEWRELIC_SERVICE_NAME")
	keyName := os.Getenv("NEWRELIC_KEY_NAME")
	appName := os.Getenv("NEWRELIC_APP_NAME")
	service, err := appEnv.Services.WithName(serviceName)

	if err != nil {
		panic(fmt.Sprintf("new relic service name error: %s", err.Error()))
	}
	s.Key = service.Credentials[keyName].(string)
	s.App = service.Credentials[appName].(string)
	return s
}
652803
func NewBindTransceiverResp() Body {
	b := newBindResp(&Header{ID: BindTransceiverRespID})
	b.init()
	return b
}
1159157
func NewQuietWrap(req *http.Request, code int32, detail string) error {
	return errors.Wrap(&Error{
		silent:   true,
		redirect: false,
		source:   req.URL.String(),
		request:  req,
		err:      newAPIError(code, detail),
	}, 1)
}
1063696
func NewURLSigner(authType string, privKey string) *URLSigner {
	return &URLSigner{
		authType: authType,
		privKey:  privKey,
	}
}
379224
func NewRBDProvisioner(client kubernetes.Interface, id string, timeout int, usePVName bool) controller.Provisioner {
	return &rbdProvisioner{
		client:   client,
		identity: id,
		rbdUtil: &RBDUtil{
			timeout: timeout,
		},
		usePVName: usePVName,
	}
}
852060
func NewRepo(repo eh.ReadWriteRepo) *Repo {
	return &Repo{
		ReadWriteRepo: repo,
		cache:         map[namespace]map[uuid.UUID]eh.Entity{},
	}
}
508735
func (r *RPCWrapper) NewRPCClient(contextID string, channel string, sharedsecret string) error {

	r.Lock()
	defer r.Unlock()

	max := maxRetries
	retries := os.Getenv(envRetryString)
	if len(retries) > 0 {
		max, _ = strconv.Atoi(retries)
	}

	numRetries := 0
	client, err := rpc.DialHTTP("unix", channel)
	for err != nil {
		numRetries++
		if numRetries >= max {
			return err
		}

		time.Sleep(5 * time.Millisecond)
		client, err = rpc.DialHTTP("unix", channel)
	}

	r.rpcClientMap.AddOrUpdate(contextID, &RPCHdl{Client: client, Channel: channel, Secret: sharedsecret})

	return nil

}
1159674
func NewEmptyLink(label string) *Link {
	return &Link{Link: model.Link{Label: label}}
}
6249
func NewDeliverSMResp() Body {
	b := newDeliverSMResp(&Header{ID: DeliverSMRespID})
	b.init()
	return b
}