MCPcopy Create free account
hub / github.com/astercloud/aster / UpdatePolicy

Method UpdatePolicy

pkg/security/policy.go:489–525  ·  view source on GitHub ↗

UpdatePolicy 更新策略

(policy *SecurityPolicy)

Source from the content-addressed store, hash-verified

487
488// UpdatePolicy 更新策略
489func (bpe *BasicPolicyEngine) UpdatePolicy(policy *SecurityPolicy) error {
490 bpe.mu.Lock()
491 defer bpe.mu.Unlock()
492
493 if policy.ID == "" {
494 return errors.New("policy ID is required")
495 }
496
497 existing, exists := bpe.policies[policy.ID]
498 if !exists {
499 return fmt.Errorf("policy %s not found", policy.ID)
500 }
501
502 // 更新时间戳
503 policy.UpdatedAt = time.Now()
504 policy.CreatedAt = existing.CreatedAt // 保持创建时间
505 policy.CreatedBy = existing.CreatedBy // 保持创建者
506
507 bpe.policies[policy.ID] = policy
508
509 // 记录审计日志
510 if bpe.config.EnableAudit && bpe.auditLog != nil {
511 _ = bpe.auditLog.LogEvent(AuditEvent{
512 Type: AuditTypePolicyUpdated,
513 UserID: policy.UpdatedBy,
514 Timestamp: time.Now(),
515 Message: fmt.Sprintf("Policy %s (%s) updated", policy.ID, policy.Name),
516 Metadata: map[string]any{
517 "policy_id": policy.ID,
518 "policy_name": policy.Name,
519 "policy_version": policy.Version,
520 },
521 })
522 }
523
524 return nil
525}
526
527// DeletePolicy 删除策略
528func (bpe *BasicPolicyEngine) DeletePolicy(policyID string) error {

Callers 1

Calls 1

LogEventMethod · 0.65

Tested by 1