Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursnerdly committed Dec 3, 2024
1 parent 673e8d9 commit 15c5ad2
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions cyral/internal/policy/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,15 @@ func updateSchema(p *msg.Policy, ptype msg.PolicyType, d *schema.ResourceData) e
}

func timestampFromResourceData(key string, d *schema.ResourceData) (*timestamppb.Timestamp, error) {
if v, ok := d.GetOk(key); ok {
ts := v.(string)
if ts == "" {
return nil, nil
}
if t, err := time.Parse(time.RFC3339, ts); err != nil {
return nil, fmt.Errorf("invalid valid_from value: %s", ts)
} else {
return timestamppb.New(t), nil
}
ts := d.Get(key).(string)
if ts == "" {
return nil, nil
}
return nil, nil
t, err := time.Parse(time.RFC3339, ts)
if err != nil {
return nil, fmt.Errorf("invalid %s value: %s", key, ts)
}
return timestamppb.New(t), nil
}

func timestampFromProtobuf(ts *timestamppb.Timestamp) string {
Expand All @@ -116,7 +113,7 @@ func timestampFromProtobuf(ts *timestamppb.Timestamp) string {
func policyAndTypeFromSchema(d *schema.ResourceData) (*msg.Policy, msg.PolicyType, error) {
ptypeString := d.Get("type").(string)
ptype := msg.PolicyType(msg.PolicyType_value[ptypeString])
if ptype == msg.PolicyType_POLICY_TYPE_UNSPECIFIED {
if ptype == msg.PolicyType_POLICY_TYPE_UNSPECIFIED || ptype == msg.PolicyType_rego {
return nil, msg.PolicyType_POLICY_TYPE_UNSPECIFIED, fmt.Errorf(
"invalid policy type: %s", ptypeString,
)
Expand Down Expand Up @@ -150,10 +147,9 @@ func scopeFromInterface(s []interface{}) *msg.Scope {
return nil
}
m := s[0].(map[string]interface{})
scope := msg.Scope{
return &msg.Scope{
RepoIds: utils.ConvertFromInterfaceList[string](m["repo_ids"].([]interface{})),
}
return &scope
}

func createPolicy(ctx context.Context, cl *client.Client, rd *schema.ResourceData) error {
Expand Down Expand Up @@ -202,8 +198,11 @@ func updatePolicy(ctx context.Context, cl *client.Client, rd *schema.ResourceDat
Policy: p,
}
grpcClient := methods.NewPolicyServiceClient(cl.GRPCClient())
_, err = grpcClient.UpdatePolicy(ctx, req)
return err
resp, err := grpcClient.UpdatePolicy(ctx, req)
if err != nil {
return err
}
return updateSchema(resp.GetPolicy(), ptype, rd)
}

func deletePolicy(ctx context.Context, cl *client.Client, rd *schema.ResourceData) error {
Expand Down

0 comments on commit 15c5ad2

Please sign in to comment.