// UpdateTarget checks to see if the authorizer on context has write access to the scraper target provided.
194094
func (s *ScraperTargetStoreService) UpdateTarget(ctx context.Context, upd *influxdb.ScraperTarget, userID influxdb.ID) (*influxdb.ScraperTarget, error) {
	st, err := s.s.GetTargetByID(ctx, upd.ID)
	if err != nil {
		return nil, err
	}

	if err := authorizeWriteScraper(ctx, st.OrgID, upd.ID); err != nil {
		return nil, err
	}

	return s.s.UpdateTarget(ctx, upd, userID)
}
293699
func (p *BlockPrefetchClient) retarget(hash string) {
	if hash == "" {
		return
	}

	if p.next.headerResult != nil && hash == p.next.headerResult.Hash {
		return
	}
	// Do not go backwards
	if p.current.headerResult != nil && hash == p.current.headerResult.Hash {
		return
	}

	h, err := chainhash.NewHashFromStr(hash)
	if err != nil {
		log.Errorf("Invalid hash %s: %v", hash, err)
		return
	}

	p.retargetChan <- h
}
307204
func (s *ScraperService) ListTargets(ctx context.Context, filter influxdb.ScraperTargetFilter) ([]influxdb.ScraperTarget, error) {
	url, err := newURL(s.Addr, targetsPath)
	if err != nil {
		return nil, err
	}

	query := url.Query()
	if filter.IDs != nil {
		for id := range filter.IDs {
			query.Add("id", id.String())
		}
	}
	if filter.Name != nil {
		query.Set("name", *filter.Name)
	}
	if filter.OrgID != nil {
		query.Set("orgID", filter.OrgID.String())
	}
	if filter.Org != nil {
		query.Set("org", *filter.Org)
	}

	req, err := http.NewRequest("GET", url.String(), nil)
	if err != nil {
		return nil, err
	}

	req.URL.RawQuery = query.Encode()
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)
	resp, err := hc.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if err := CheckError(resp); err != nil {
		return nil, err
	}

	var targetsResp getTargetsResponse
	if err := json.NewDecoder(resp.Body).Decode(&targetsResp); err != nil {
		return nil, err
	}

	targets := make([]influxdb.ScraperTarget, len(targetsResp.Targets))
	for k, v := range targetsResp.Targets {
		targets[k] = v.ScraperTarget
	}

	return targets, nil
}
1255173
func (config *Config) SetTargetInformation(api string, apiVersion string, auth string, minCLIVersion string, doppler string, routing string, skipSSLValidation bool) {
	config.ConfigFile.Target = api
	config.ConfigFile.APIVersion = apiVersion
	config.ConfigFile.AuthorizationEndpoint = auth
	config.SetMinCLIVersion(minCLIVersion)
	config.ConfigFile.DopplerEndpoint = doppler
	config.ConfigFile.RoutingEndpoint = routing
	config.ConfigFile.SkipSSLValidation = skipSSLValidation

	config.UnsetOrganizationAndSpaceInformation()
}
853360
func (u *Update) Target(path string) *Update {
	u.TargetPath = path
	return u
}
43549
func (c *Client) AddTarget(ctx context.Context, target *influxdb.ScraperTarget, userID influxdb.ID) (err error) {
	if !target.OrgID.Valid() {
		return &influxdb.Error{
			Code: influxdb.EInvalid,
			Msg:  "provided organization ID has invalid format",
			Op:   OpPrefix + influxdb.OpAddTarget,
		}
	}
	if !target.BucketID.Valid() {
		return &influxdb.Error{
			Code: influxdb.EInvalid,
			Msg:  "provided bucket ID has invalid format",
			Op:   OpPrefix + influxdb.OpAddTarget,
		}
	}
	err = c.db.Update(func(tx *bolt.Tx) error {
		target.ID = c.IDGenerator.ID()
		if err := c.putTarget(ctx, tx, target); err != nil {
			return err
		}
		urm := &influxdb.UserResourceMapping{
			ResourceID:   target.ID,
			UserID:       userID,
			UserType:     influxdb.Owner,
			ResourceType: influxdb.ScraperResourceType,
		}
		return c.createUserResourceMapping(ctx, tx, urm)
	})
	if err != nil {
		return &influxdb.Error{
			Err: err,
			Op:  OpPrefix + influxdb.OpAddTarget,
		}
	}
	return nil
}
571897
func (s *ListAttachedPoliciesInput) SetTarget(v string) *ListAttachedPoliciesInput {
	s.Target = &v
	return s
}
178033
func (s *UpdateRouteInput) SetTarget(v string) *UpdateRouteInput {
	s.Target = &v
	return s
}
1256255
func (s *UpdateCrawlerInput) SetTargets(v *CrawlerTargets) *UpdateCrawlerInput {
	s.Targets = v
	return s
}
965419
func (s *Service) UpdateTarget(ctx context.Context, update *influxdb.ScraperTarget, userID influxdb.ID) (target *influxdb.ScraperTarget, err error) {
	op := OpPrefix + influxdb.OpUpdateTarget
	if !update.ID.Valid() {
		return nil, &influxdb.Error{
			Code: influxdb.EInvalid,
			Op:   op,
			Msg:  "provided scraper target ID has invalid format",
		}
	}
	oldTarget, pe := s.loadScraperTarget(update.ID)
	if pe != nil {
		return nil, &influxdb.Error{
			Op:  op,
			Err: pe,
		}
	}
	if !update.OrgID.Valid() {
		update.OrgID = oldTarget.OrgID
	}
	if !update.BucketID.Valid() {
		update.BucketID = oldTarget.BucketID
	}
	if err = s.PutTarget(ctx, update); err != nil {
		return nil, &influxdb.Error{
			Op:  op,
			Err: pe,
		}
	}

	return update, nil
}
619380
func (s *WebhookDefinition) SetTargetAction(v string) *WebhookDefinition {
	s.TargetAction = &v
	return s
}
158989
func (s *Service) PutTarget(ctx context.Context, target *influxdb.ScraperTarget) error {
	s.scraperTargetKV.Store(target.ID.String(), *target)
	return nil
}
1035351
func (s *ScraperTargetStoreService) GetTargetByID(ctx context.Context, id influxdb.ID) (*influxdb.ScraperTarget, error) {
	st, err := s.s.GetTargetByID(ctx, id)
	if err != nil {
		return nil, err
	}

	if err := authorizeReadScraper(ctx, st.OrgID, id); err != nil {
		return nil, err
	}

	return st, nil
}
810557
func (s *ScraperTargetStoreService) AddTarget(ctx context.Context, t *platform.ScraperTarget) error {
	return s.AddTargetF(ctx, t)
}
281488
func (s *PutScalingPolicyInput) SetTargetConfiguration(v *TargetConfiguration) *PutScalingPolicyInput {
	s.TargetConfiguration = v
	return s
}
298491
func (s *CreateRouteInput) SetTarget(v string) *CreateRouteInput {
	s.Target = &v
	return s
}
10980
func (s *Service) UpdateTarget(ctx context.Context, update *influxdb.ScraperTarget, userID influxdb.ID) (*influxdb.ScraperTarget, error) {
	var target *influxdb.ScraperTarget
	err := s.kv.Update(ctx, func(tx Tx) error {
		var err error
		target, err = s.updateTarget(ctx, tx, update, userID)
		return err
	})

	return target, err
}