// AddTarget creates a new scraper target and sets target.ID with the new identifier.
190213
func (s *ScraperService) AddTarget(ctx context.Context, target *platform.ScraperTarget) error {
	url, err := newURL(s.Addr, targetPath)
	if err != nil {
		return err
	}

	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
	}

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

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

	return nil
}
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
}
302226
func (s *Service) AddTarget(ctx context.Context, target *influxdb.ScraperTarget, userID influxdb.ID) (err error) {
	return s.kv.Update(ctx, func(tx Tx) error {
		return s.addTarget(ctx, tx, target, userID)
	})
}
799068
func (s *AutomationExecution) SetTarget(v string) *AutomationExecution {
	s.Target = &v
	return s
}
96948
func (s *ScraperService) UpdateTarget(ctx context.Context, update *influxdb.ScraperTarget, userID influxdb.ID) (*influxdb.ScraperTarget, error) {
	if !update.ID.Valid() {
		return nil, &influxdb.Error{
			Code: influxdb.EInvalid,
			Op:   s.OpPrefix + influxdb.OpUpdateTarget,
			Msg:  "provided scraper target ID has invalid format",
		}
	}
	url, err := newURL(s.Addr, targetIDPath(update.ID))
	if err != nil {
		return nil, err
	}

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

	req, err := http.NewRequest("PATCH", url.String(), bytes.NewReader(octets))
	if err != nil {
		return nil, 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 nil, err
	}
	defer resp.Body.Close()

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

	return &targetResp.ScraperTarget, nil
}
571897
func (s *ListAttachedPoliciesInput) SetTarget(v string) *ListAttachedPoliciesInput {
	s.Target = &v
	return s
}
364851
func (s *DetachPolicyInput) SetTarget(v string) *DetachPolicyInput {
	s.Target = &v
	return s
}
1047216
func (p *Panel) SetTarget(t *Target) {
	setTarget := func(t *Target, targets *[]Target) {
		for i, target := range *targets {
			if t.RefID == target.RefID {
				(*targets)[i] = *t
				return
			}
		}
		(*targets) = append((*targets), *t)
	}
	switch p.OfType {
	case GraphType:
		setTarget(t, &p.GraphPanel.Targets)
	case SinglestatType:
		setTarget(t, &p.SinglestatPanel.Targets)
	case TableType:
		setTarget(t, &p.TablePanel.Targets)
	}
}
253799
func (s *CopyClusterSnapshotInput) SetTargetSnapshotIdentifier(v string) *CopyClusterSnapshotInput {
	s.TargetSnapshotIdentifier = &v
	return s
}
622381
func (s *ProgressDetail) SetTargetResource(v string) *ProgressDetail {
	s.TargetResource = &v
	return s
}
1148966
func (s *PutTargetsResultEntry) SetTargetId(v string) *PutTargetsResultEntry {
	s.TargetId = &v
	return s
}
310258
func (s *Service) UpdateTarget(ctx context.Context, update *platform.ScraperTarget) (target *platform.ScraperTarget, err error) {
	op := OpPrefix + platform.OpUpdateTarget
	if !update.ID.Valid() {
		return nil, &platform.Error{
			Code: platform.EInvalid,
			Op:   op,
			Msg:  "id is invalid",
		}
	}
	_, pe := s.loadScraperTarget(update.ID)
	if pe != nil {
		return nil, &platform.Error{
			Op:  op,
			Err: pe,
		}
	}
	if err = s.PutTarget(ctx, update); err != nil {
		return nil, &platform.Error{
			Op:  op,
			Err: pe,
		}
	}

	return update, nil
}
298491
func (s *CreateRouteInput) SetTarget(v string) *CreateRouteInput {
	s.Target = &v
	return s
}
1343423
func (i *iscsiConnectionInfo) addTarget() error {
	newNodeParams := []string{
		"iscsiadm", "-m", "node",
		"-o", "new",
		"-T", i.iqn,
		"-p", i.portal()}
	result, err := runCommand(newNodeParams)
	if err != nil {
		return errors.Annotatef(err, "iscsiadm failed to add new node: %s", result.Stderr)
	}

	startupParams := []string{
		"iscsiadm", "-m", "node",
		"-o", "update",
		"-T", i.iqn,
		"-n", "node.startup",
		"-v", "automatic"}
	result, err = runCommand(startupParams)
	if err != nil {
		return errors.Annotatef(err, "iscsiadm failed to set startup mode: %s", result.Stderr)
	}

	if i.chapSecret != "" && i.chapUser != "" {
		authModeParams := []string{
			"iscsiadm", "-m", "node",
			"-o", "update",
			"-T", i.iqn,
			"-p", i.portal(),
			"-n", "node.session.auth.authmethod",
			"-v", "CHAP",
		}
		result, err = runCommand(authModeParams)
		if err != nil {
			return errors.Annotatef(err, "iscsiadm failed to set auth method: %s", result.Stderr)
		}
		usernameParams := []string{
			"iscsiadm", "-m", "node",
			"-o", "update",
			"-T", i.iqn,
			"-p", i.portal(),
			"-n", "node.session.auth.username",
			"-v", i.chapUser,
		}
		result, err = runCommand(usernameParams)
		if err != nil {
			return errors.Annotatef(err, "iscsiadm failed to set auth username: %s", result.Stderr)
		}
		passwordParams := []string{
			"iscsiadm", "-m", "node",
			"-o", "update",
			"-T", i.iqn,
			"-p", i.portal(),
			"-n", "node.session.auth.password",
			"-v", i.chapSecret,
		}
		result, err = runCommand(passwordParams)
		if err != nil {
			return errors.Annotatef(err, "iscsiadm failed to set auth password: %s", result.Stderr)
		}
	}
	return nil
}
492528
func (s *InviteAccountToOrganizationInput) SetTarget(v *HandshakeParty) *InviteAccountToOrganizationInput {
	s.Target = v
	return s
}
854554
func (s *ListSigningPlatformsInput) SetTarget(v string) *ListSigningPlatformsInput {
	s.Target = &v
	return s
}
809010
func (s *CreateDocumentInput) SetTargetType(v string) *CreateDocumentInput {
	s.TargetType = &v
	return s
}