// UpdateTarget updates a scraper target.
353042
func (c *Client) UpdateTarget(ctx context.Context, update *influxdb.ScraperTarget, userID influxdb.ID) (target *influxdb.ScraperTarget, err error) {
	op := getOp(influxdb.OpUpdateTarget)
	var pe *influxdb.Error
	if !update.ID.Valid() {
		return nil, &influxdb.Error{
			Code: influxdb.EInvalid,
			Op:   op,
			Msg:  "provided scraper target ID has invalid format",
		}
	}
	err = c.db.Update(func(tx *bolt.Tx) error {
		target, pe = c.findTargetByID(ctx, tx, update.ID)
		if pe != nil {
			return pe
		}
		if !update.BucketID.Valid() {
			update.BucketID = target.BucketID
		}
		if !update.OrgID.Valid() {
			update.OrgID = target.OrgID
		}
		target = update
		return c.putTarget(ctx, tx, target)
	})

	if err != nil {
		return nil, &influxdb.Error{
			Op:  op,
			Err: err,
		}
	}

	return target, nil
}
912738
func (r *repository) AddTarget(target *Target, roles ...data.RoleName) error {
	if len(target.Hashes) == 0 {
		return fmt.Errorf("no hashes specified for target \"%s\"", target.Name)
	}
	logrus.Debugf("Adding target \"%s\" with sha256 \"%x\" and size %d bytes.\n", target.Name, target.Hashes["sha256"], target.Length)

	meta := data.FileMeta{Length: target.Length, Hashes: target.Hashes, Custom: target.Custom}
	metaJSON, err := json.Marshal(meta)
	if err != nil {
		return err
	}

	template := changelist.NewTUFChange(
		changelist.ActionCreate, "", changelist.TypeTargetsTarget,
		target.Name, metaJSON)
	return addChange(r.changelist, template, roles...)
}
1286849
func (s *Service) ListTargets(ctx context.Context) (list []platform.ScraperTarget, err error) {
	list = make([]platform.ScraperTarget, 0)
	s.scraperTargetKV.Range(func(_, v interface{}) bool {
		b, ok := v.(platform.ScraperTarget)
		if !ok {
			err = &platform.Error{
				Code: platform.EInvalid,
				Msg:  fmt.Sprintf("type %T is not a scraper target", v),
			}
			return false
		}
		list = append(list, b)
		return true
	})
	return list, err
}
298491
func (s *CreateRouteInput) SetTarget(v string) *CreateRouteInput {
	s.Target = &v
	return s
}
80634
func (s *ScraperService) AddTarget(ctx context.Context, target *influxdb.ScraperTarget, userID influxdb.ID) error {
	url, err := newURL(s.Addr, targetsPath)
	if err != nil {
		return err
	}

	if !target.OrgID.Valid() {
		return &influxdb.Error{
			Code: influxdb.EInvalid,
			Msg:  "provided organization ID has invalid format",
			Op:   s.OpPrefix + influxdb.OpAddTarget,
		}
	}
	if !target.BucketID.Valid() {
		return &influxdb.Error{
			Code: influxdb.EInvalid,
			Msg:  "provided bucket ID has invalid format",
			Op:   s.OpPrefix + influxdb.OpAddTarget,
		}
	}

	octets, err := json.Marshal(target)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	// TODO(jsternberg): Should this check for a 201 explicitly?
	if err := CheckError(resp); err != nil {
		return err
	}

	targetResp := new(targetResponse)
	if err := json.NewDecoder(resp.Body).Decode(targetResp); err != nil {
		return err
	}

	return nil
}
1005989
func (c *Client) AddTarget(ctx context.Context, target *platform.ScraperTarget) (err error) {
	err = c.db.Update(func(tx *bolt.Tx) error {
		target.ID = c.IDGenerator.ID()
		return c.putTarget(ctx, tx, target)
	})
	if err != nil {
		return &platform.Error{
			Err: err,
			Op:  OpPrefix + platform.OpAddTarget,
		}
	}
	return nil
}
782603
func (s *Service) AddTarget(ctx context.Context, target *platform.ScraperTarget) (err error) {
	target.ID = s.IDGenerator.ID()
	if err := s.PutTarget(ctx, target); err != nil {
		return &platform.Error{
			Op:  OpPrefix + platform.OpAddTarget,
			Err: err,
		}
	}
	return nil
}
854554
func (s *ListSigningPlatformsInput) SetTarget(v string) *ListSigningPlatformsInput {
	s.Target = &v
	return s
}
1317860
func (s *Service) RemoveTarget(ctx context.Context, id influxdb.ID) error {
	if _, pe := s.loadScraperTarget(id); pe != nil {
		return &influxdb.Error{
			Err: pe,
			Op:  OpPrefix + influxdb.OpRemoveTarget,
		}
	}
	s.scraperTargetKV.Delete(id.String())
	err := s.deleteUserResourceMapping(ctx, influxdb.UserResourceMappingFilter{
		ResourceID:   id,
		ResourceType: influxdb.ScraperResourceType,
	})
	if err != nil {
		return &influxdb.Error{
			Code: influxdb.ErrorCode(err),
			Op:   OpPrefix + influxdb.OpRemoveTarget,
			Err:  err,
		}
	}

	return nil
}
864669
func (s *CreateRouteOutput) SetTarget(v string) *CreateRouteOutput {
	s.Target = &v
	return s
}
554884
func (m *Machine) UpgradeSeriesTarget() (string, error) {
	lock, err := m.getUpgradeSeriesLock()
	if err != nil {
		return "", errors.Trace(err)
	}
	return lock.ToSeries, nil
}
973092
func (c *Client) PutTarget(ctx context.Context, target *platform.ScraperTarget) error {
	return c.db.Update(func(tx *bolt.Tx) error {
		return c.putTarget(ctx, tx, target)
	})
}
760503
func (s *RemediationConfiguration) SetTargetVersion(v string) *RemediationConfiguration {
	s.TargetVersion = &v
	return s
}
1324938
func (s *UpgradeElasticsearchDomainOutput) SetTargetVersion(v string) *UpgradeElasticsearchDomainOutput {
	s.TargetVersion = &v
	return s
}
622381
func (s *ProgressDetail) SetTargetResource(v string) *ProgressDetail {
	s.TargetResource = &v
	return s
}
1296371
func (s *CopySnapshotInput) SetTargetSnapshotName(v string) *CopySnapshotInput {
	s.TargetSnapshotName = &v
	return s
}
330321
func (c *Client) RemoveTarget(ctx context.Context, id platform.ID) error {
	err := c.db.Update(func(tx *bolt.Tx) error {
		_, pe := c.findTargetByID(ctx, tx, id)
		if pe != nil {
			return pe
		}
		encID, err := id.Encode()
		if err != nil {
			return &platform.Error{
				Code: platform.EInvalid,
				Err:  err,
			}
		}
		return tx.Bucket(scraperBucket).Delete(encID)
	})
	if err != nil {
		return &platform.Error{
			Err: err,
			Op:  OpPrefix + platform.OpRemoveTarget,
		}
	}
	return nil
}