MCPcopy
hub / github.com/harness/harness / RuleCreate

Method RuleCreate

app/api/controller/space/rule_create.go:28–52  ·  view source on GitHub ↗

RuleCreate creates a new protection rule for a space.

(ctx context.Context,
	session *auth.Session,
	spaceRef string,
	in *rules.CreateInput,
)

Source from the content-addressed store, hash-verified

26
27// RuleCreate creates a new protection rule for a space.
28func (c *Controller) RuleCreate(ctx context.Context,
29 session *auth.Session,
30 spaceRef string,
31 in *rules.CreateInput,
32) (*types.Rule, error) {
33 space, err := c.getSpaceCheckAuth(ctx, session, spaceRef, enum.PermissionSpaceEdit)
34 if err != nil {
35 return nil, fmt.Errorf("failed to acquire access to space: %w", err)
36 }
37
38 rule, err := c.rulesSvc.Create(
39 ctx,
40 &session.Principal,
41 enum.RuleParentSpace,
42 space.ID,
43 space.Identifier,
44 space.Path,
45 in,
46 )
47 if err != nil {
48 return nil, fmt.Errorf("failed to create space-level protection rule: %w", err)
49 }
50
51 return rule, nil
52}

Callers

nothing calls this directly

Calls 3

getSpaceCheckAuthMethod · 0.95
CreateMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected