• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

goto / guardian / 18086206500

29 Sep 2025 04:54AM UTC coverage: 68.845%. First build
18086206500

Pull #225

github

anjaliagg9791
chore: fix logger
Pull Request #225: feat: add support for custom policy steps

145 of 227 new or added lines in 8 files covered. (63.88%)

11484 of 16681 relevant lines covered (68.84%)

4.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.6
/api/handler/v1beta1/adapter.go
1
package v1beta1
2

3
import (
4
        "fmt"
5

6
        "github.com/mitchellh/mapstructure"
7
        "google.golang.org/protobuf/types/known/structpb"
8
        "google.golang.org/protobuf/types/known/timestamppb"
9

10
        guardianv1beta1 "github.com/goto/guardian/api/proto/gotocompany/guardian/v1beta1"
11
        "github.com/goto/guardian/domain"
12
)
13

14
type adapter struct{}
15

16
func NewAdapter() *adapter {
134✔
17
        return &adapter{}
134✔
18
}
134✔
19

20
func (a *adapter) FromProviderProto(p *guardianv1beta1.Provider) (*domain.Provider, error) {
×
21
        provider := &domain.Provider{
×
22
                ID:   p.GetId(),
×
23
                Type: p.GetType(),
×
24
                URN:  p.GetUrn(),
×
25
        }
×
26

×
27
        if p.GetConfig() != nil {
×
28
                provider.Config = a.FromProviderConfigProto(p.GetConfig())
×
29
        }
×
30

31
        if p.GetCreatedAt() != nil {
×
32
                provider.CreatedAt = p.GetCreatedAt().AsTime()
×
33
        }
×
34
        if p.GetUpdatedAt() != nil {
×
35
                provider.UpdatedAt = p.GetUpdatedAt().AsTime()
×
36
        }
×
37

38
        return provider, nil
×
39
}
40

41
func (a *adapter) FromProviderConfigProto(pc *guardianv1beta1.ProviderConfig) *domain.ProviderConfig {
6✔
42
        providerConfig := &domain.ProviderConfig{
6✔
43
                Type:        pc.GetType(),
6✔
44
                URN:         pc.GetUrn(),
6✔
45
                Labels:      pc.GetLabels(),
6✔
46
                Credentials: pc.GetCredentials().AsInterface(),
6✔
47
        }
6✔
48

6✔
49
        if pc.GetAppeal() != nil {
7✔
50
                appealConfig := &domain.AppealConfig{}
1✔
51
                appealConfig.AllowPermanentAccess = pc.GetAppeal().GetAllowPermanentAccess()
1✔
52
                appealConfig.AllowActiveAccessExtensionIn = pc.GetAppeal().GetAllowActiveAccessExtensionIn()
1✔
53
                providerConfig.Appeal = appealConfig
1✔
54
        }
1✔
55

56
        if pc.GetResources() != nil {
8✔
57
                resources := []*domain.ResourceConfig{}
2✔
58
                for _, r := range pc.GetResources() {
4✔
59
                        roles := []*domain.Role{}
2✔
60
                        for _, roleProto := range r.GetRoles() {
4✔
61
                                role := &domain.Role{
2✔
62
                                        ID:          roleProto.GetId(),
2✔
63
                                        Name:        roleProto.GetName(),
2✔
64
                                        Description: roleProto.GetDescription(),
2✔
65
                                }
2✔
66

2✔
67
                                if roleProto.Permissions != nil {
2✔
68
                                        permissions := []interface{}{}
×
69
                                        for _, p := range roleProto.GetPermissions() {
×
70
                                                permissions = append(permissions, p.AsInterface())
×
71
                                        }
×
72
                                        role.Permissions = permissions
×
73
                                }
74

75
                                roles = append(roles, role)
2✔
76
                        }
77

78
                        resources = append(resources, &domain.ResourceConfig{
2✔
79
                                Type:   r.GetType(),
2✔
80
                                Filter: r.GetFilter(),
2✔
81
                                Policy: a.fromPolicyConfigProto(r.GetPolicy()),
2✔
82
                                Roles:  roles,
2✔
83
                        })
2✔
84
                }
85
                providerConfig.Resources = resources
2✔
86
        }
87

88
        if pc.GetParameters() != nil {
7✔
89
                parameters := []*domain.ProviderParameter{}
1✔
90
                for _, p := range pc.GetParameters() {
2✔
91
                        parameters = append(parameters, &domain.ProviderParameter{
1✔
92
                                Key:         p.GetKey(),
1✔
93
                                Label:       p.GetLabel(),
1✔
94
                                Required:    p.GetRequired(),
1✔
95
                                Description: p.GetDescription(),
1✔
96
                        })
1✔
97
                }
1✔
98
                providerConfig.Parameters = parameters
1✔
99
        }
100

101
        if pc.GetAllowedAccountTypes() != nil {
8✔
102
                providerConfig.AllowedAccountTypes = pc.GetAllowedAccountTypes()
2✔
103
        }
2✔
104

105
        if pc.GetPolicies() != nil {
8✔
106
                policies := []*domain.ProviderPolicy{}
2✔
107
                for _, p := range pc.GetPolicies() {
4✔
108
                        policies = append(policies, &domain.ProviderPolicy{
2✔
109
                                When:   p.GetWhen(),
2✔
110
                                Policy: p.GetPolicy(),
2✔
111
                        })
2✔
112
                }
2✔
113
                providerConfig.Policies = policies
2✔
114
        }
115

116
        return providerConfig
6✔
117
}
118

119
func (a *adapter) ToProviderProto(p *domain.Provider) (*guardianv1beta1.Provider, error) {
8✔
120
        providerProto := &guardianv1beta1.Provider{
8✔
121
                Id:   p.ID,
8✔
122
                Type: p.Type,
8✔
123
                Urn:  p.URN,
8✔
124
        }
8✔
125

8✔
126
        if p.Config != nil {
16✔
127
                config, err := a.ToProviderConfigProto(p.Config)
8✔
128
                if err != nil {
12✔
129
                        return nil, err
4✔
130
                }
4✔
131
                providerProto.Config = config
4✔
132
        }
133

134
        if !p.CreatedAt.IsZero() {
8✔
135
                providerProto.CreatedAt = timestamppb.New(p.CreatedAt)
4✔
136
        }
4✔
137
        if !p.UpdatedAt.IsZero() {
8✔
138
                providerProto.UpdatedAt = timestamppb.New(p.UpdatedAt)
4✔
139
        }
4✔
140

141
        return providerProto, nil
4✔
142
}
143

144
func (a *adapter) ToProviderConfigProto(pc *domain.ProviderConfig) (*guardianv1beta1.ProviderConfig, error) {
8✔
145
        providerConfigProto := &guardianv1beta1.ProviderConfig{
8✔
146
                Type:   pc.Type,
8✔
147
                Urn:    pc.URN,
8✔
148
                Labels: pc.Labels,
8✔
149
        }
8✔
150

8✔
151
        if pc.Credentials != nil {
11✔
152
                credentials, err := structpb.NewValue(pc.Credentials)
3✔
153
                if err != nil {
6✔
154
                        return nil, err
3✔
155
                }
3✔
156
                providerConfigProto.Credentials = credentials
×
157
        }
158

159
        if pc.Appeal != nil {
7✔
160
                providerConfigProto.Appeal = &guardianv1beta1.ProviderConfig_AppealConfig{
2✔
161
                        AllowPermanentAccess:         pc.Appeal.AllowPermanentAccess,
2✔
162
                        AllowActiveAccessExtensionIn: pc.Appeal.AllowActiveAccessExtensionIn,
2✔
163
                }
2✔
164
        }
2✔
165

166
        if pc.Resources != nil {
10✔
167
                resources := []*guardianv1beta1.ProviderConfig_ResourceConfig{}
5✔
168
                for _, rc := range pc.Resources {
10✔
169
                        roles := []*guardianv1beta1.Role{}
5✔
170
                        for _, role := range rc.Roles {
10✔
171
                                roleProto, err := a.ToRole(role)
5✔
172
                                if err != nil {
6✔
173
                                        return nil, err
1✔
174
                                }
1✔
175
                                roles = append(roles, roleProto)
4✔
176
                        }
177

178
                        resources = append(resources, &guardianv1beta1.ProviderConfig_ResourceConfig{
4✔
179
                                Type:   rc.Type,
4✔
180
                                Policy: a.toPolicyConfigProto(rc.Policy),
4✔
181
                                Roles:  roles,
4✔
182
                        })
4✔
183
                }
184
                providerConfigProto.Resources = resources
4✔
185
        }
186

187
        if pc.Parameters != nil {
5✔
188
                parameters := []*guardianv1beta1.ProviderConfig_ProviderParameter{}
1✔
189
                for _, p := range pc.Parameters {
2✔
190
                        parameters = append(parameters, &guardianv1beta1.ProviderConfig_ProviderParameter{
1✔
191
                                Key:         p.Key,
1✔
192
                                Label:       p.Label,
1✔
193
                                Required:    p.Required,
1✔
194
                                Description: p.Description,
1✔
195
                        })
1✔
196
                }
1✔
197
                providerConfigProto.Parameters = parameters
1✔
198
        }
199

200
        if pc.AllowedAccountTypes != nil {
8✔
201
                providerConfigProto.AllowedAccountTypes = pc.AllowedAccountTypes
4✔
202
        }
4✔
203

204
        if pc.Policies != nil {
8✔
205
                policies := []*guardianv1beta1.ProviderPolicy{}
4✔
206
                for _, p := range pc.Policies {
8✔
207
                        policies = append(policies, &guardianv1beta1.ProviderPolicy{
4✔
208
                                Policy: p.Policy,
4✔
209
                                When:   p.When,
4✔
210
                        })
4✔
211
                }
4✔
212
                providerConfigProto.Policies = policies
4✔
213
        }
214

215
        return providerConfigProto, nil
4✔
216
}
217

218
func (a *adapter) ToProviderTypeProto(pt domain.ProviderType) *guardianv1beta1.ProviderType {
1✔
219
        return &guardianv1beta1.ProviderType{
1✔
220
                Name:          pt.Name,
1✔
221
                ResourceTypes: pt.ResourceTypes,
1✔
222
        }
1✔
223
}
1✔
224

225
func (a *adapter) ToRole(role *domain.Role) (*guardianv1beta1.Role, error) {
7✔
226
        roleProto := &guardianv1beta1.Role{
7✔
227
                Id:          role.ID,
7✔
228
                Name:        role.Name,
7✔
229
                Description: role.Description,
7✔
230
        }
7✔
231

7✔
232
        if role.Permissions != nil {
10✔
233
                permissions := []*structpb.Value{}
3✔
234
                for _, p := range role.Permissions {
6✔
235
                        permission, err := structpb.NewValue(p)
3✔
236
                        if err != nil {
5✔
237
                                return nil, err
2✔
238
                        }
2✔
239
                        permissions = append(permissions, permission)
1✔
240
                }
241
                roleProto.Permissions = permissions
1✔
242
        }
243

244
        return roleProto, nil
5✔
245
}
246

247
func (a *adapter) FromPolicyProto(p *guardianv1beta1.Policy) *domain.Policy {
8✔
248
        policy := &domain.Policy{
8✔
249
                ID:          p.GetId(),
8✔
250
                Version:     uint(p.GetVersion()),
8✔
251
                Description: p.GetDescription(),
8✔
252
                Labels:      p.GetLabels(),
8✔
253
        }
8✔
254

8✔
255
        if p.GetSteps() != nil {
10✔
256
                var steps []*domain.Step
2✔
257
                for _, s := range p.GetSteps() {
4✔
258
                        steps = append(steps, &domain.Step{
2✔
259
                                Name:                  s.GetName(),
2✔
260
                                Description:           s.GetDescription(),
2✔
261
                                When:                  s.GetWhen(),
2✔
262
                                Strategy:              domain.ApprovalStepStrategy(s.GetStrategy()),
2✔
263
                                RejectionReason:       s.GetRejectionReason(),
2✔
264
                                ApproveIf:             s.GetApproveIf(),
2✔
265
                                AllowFailed:           s.GetAllowFailed(),
2✔
266
                                Approvers:             s.GetApprovers(),
2✔
267
                                DontAllowSelfApproval: s.GetDontAllowSelfApproval(),
2✔
268
                        })
2✔
269
                }
2✔
270
                policy.Steps = steps
2✔
271
        }
272

273
        if cs := p.GetCustomSteps(); cs != nil {
8✔
NEW
274
                policy.CustomSteps = &domain.CustomSteps{
×
NEW
275
                        Type:   cs.GetType(),
×
NEW
276
                        Config: cs.GetConfig(),
×
NEW
277
                }
×
NEW
278
        }
×
279

280
        if p.GetRequirements() != nil {
10✔
281
                var requirements []*domain.Requirement
2✔
282
                for _, r := range p.GetRequirements() {
4✔
283
                        var on *domain.RequirementTrigger
2✔
284
                        if r.GetOn() != nil {
4✔
285
                                var conditions []*domain.Condition
2✔
286
                                if r.GetOn().GetConditions() != nil {
2✔
287
                                        for _, c := range r.GetOn().GetConditions() {
×
288
                                                conditions = append(conditions, a.fromConditionProto(c))
×
289
                                        }
×
290
                                }
291

292
                                on = &domain.RequirementTrigger{
2✔
293
                                        ProviderType: r.GetOn().GetProviderType(),
2✔
294
                                        ProviderURN:  r.GetOn().GetProviderUrn(),
2✔
295
                                        ResourceType: r.GetOn().GetResourceType(),
2✔
296
                                        ResourceURN:  r.GetOn().GetResourceUrn(),
2✔
297
                                        Role:         r.GetOn().GetRole(),
2✔
298
                                        Conditions:   conditions,
2✔
299
                                        Expression:   r.GetOn().GetExpression(),
2✔
300
                                }
2✔
301
                        }
302

303
                        var additionalAppeals []*domain.AdditionalAppeal
2✔
304
                        if r.GetAppeals() != nil {
4✔
305
                                for _, aa := range r.GetAppeals() {
4✔
306
                                        var resource *domain.ResourceIdentifier
2✔
307
                                        if aa.GetResource() != nil {
4✔
308
                                                resource = &domain.ResourceIdentifier{
2✔
309
                                                        ProviderType: aa.GetResource().GetProviderType(),
2✔
310
                                                        ProviderURN:  aa.GetResource().GetProviderUrn(),
2✔
311
                                                        Type:         aa.GetResource().GetType(),
2✔
312
                                                        URN:          aa.GetResource().GetUrn(),
2✔
313
                                                        ID:           aa.GetResource().GetId(),
2✔
314
                                                }
2✔
315
                                        }
2✔
316

317
                                        additionalAppeals = append(additionalAppeals, &domain.AdditionalAppeal{
2✔
318
                                                Resource:    resource,
2✔
319
                                                Role:        aa.GetRole(),
2✔
320
                                                Options:     a.fromAppealOptionsProto(aa.GetOptions()),
2✔
321
                                                Policy:      a.fromPolicyConfigProto(aa.GetPolicy()),
2✔
322
                                                AccountType: aa.GetAccountType(),
2✔
323
                                        })
2✔
324
                                }
325
                        }
326

327
                        requirements = append(requirements, &domain.Requirement{
2✔
328
                                On:      on,
2✔
329
                                Appeals: additionalAppeals,
2✔
330
                        })
2✔
331
                        policy.Requirements = requirements
2✔
332
                }
333
        }
334

335
        if p.GetIam() != nil {
10✔
336
                policy.IAM = &domain.IAMConfig{
2✔
337
                        Provider: domain.IAMProviderType(p.GetIam().GetProvider()),
2✔
338
                        Config:   p.GetIam().GetConfig().AsInterface(),
2✔
339
                        Schema:   p.GetIam().GetSchema(),
2✔
340
                }
2✔
341
        }
2✔
342

343
        if p.GetAppeal() != nil {
10✔
344
                var durationOptions []domain.AppealDurationOption
2✔
345
                var questions []domain.Question
2✔
346
                var metadataSources map[string]*domain.AppealMetadataSource
2✔
347

2✔
348
                for _, d := range p.GetAppeal().GetDurationOptions() {
6✔
349
                        option := domain.AppealDurationOption{
4✔
350
                                Name:  d.GetName(),
4✔
351
                                Value: d.GetValue(),
4✔
352
                        }
4✔
353
                        durationOptions = append(durationOptions, option)
4✔
354
                }
4✔
355
                for _, q := range p.GetAppeal().GetQuestions() {
3✔
356
                        question := domain.Question{
1✔
357
                                Key:         q.GetKey(),
1✔
358
                                Question:    q.GetQuestion(),
1✔
359
                                Required:    q.GetRequired(),
1✔
360
                                Description: q.GetDescription(),
1✔
361
                        }
1✔
362
                        questions = append(questions, question)
1✔
363
                }
1✔
364

365
                if mds := p.GetAppeal().GetMetadataSources(); mds != nil {
3✔
366
                        metadataSources = make(map[string]*domain.AppealMetadataSource)
1✔
367
                        for key, metadataCfg := range mds {
2✔
368
                                metadataSources[key] = &domain.AppealMetadataSource{
1✔
369
                                        Name:        metadataCfg.GetName(),
1✔
370
                                        Description: metadataCfg.GetDescription(),
1✔
371
                                        Type:        metadataCfg.GetType(),
1✔
372
                                        Config:      metadataCfg.GetConfig().AsInterface(),
1✔
373
                                        Value:       metadataCfg.GetValue().AsInterface(),
1✔
374
                                }
1✔
375
                        }
1✔
376
                }
377

378
                policy.AppealConfig = &domain.PolicyAppealConfig{
2✔
379
                        DurationOptions:              durationOptions,
2✔
380
                        AllowOnBehalf:                p.GetAppeal().GetAllowOnBehalf(),
2✔
381
                        Questions:                    questions,
2✔
382
                        AllowPermanentAccess:         p.GetAppeal().GetAllowPermanentAccess(),
2✔
383
                        AllowActiveAccessExtensionIn: p.GetAppeal().GetAllowActiveAccessExtensionIn(),
2✔
384
                        AllowCreatorDetailsFailure:   p.GetAppeal().GetAllowCreatorDetailsFailure(),
2✔
385
                        MetadataSources:              metadataSources,
2✔
386
                }
2✔
387
        }
388

389
        if p.GetCreatedAt() != nil {
8✔
390
                policy.CreatedAt = p.GetCreatedAt().AsTime()
×
391
        }
×
392
        if p.GetUpdatedAt() != nil {
8✔
393
                policy.UpdatedAt = p.GetUpdatedAt().AsTime()
×
394
        }
×
395

396
        return policy
8✔
397
}
398

399
func (a *adapter) ToPolicyProto(p *domain.Policy) (*guardianv1beta1.Policy, error) {
8✔
400
        policyProto := &guardianv1beta1.Policy{
8✔
401
                Id:          p.ID,
8✔
402
                Version:     uint32(p.Version),
8✔
403
                Description: p.Description,
8✔
404
                Labels:      p.Labels,
8✔
405
        }
8✔
406

8✔
407
        if p.Steps != nil {
12✔
408
                var steps []*guardianv1beta1.Policy_ApprovalStep
4✔
409
                for _, s := range p.Steps {
8✔
410
                        steps = append(steps, &guardianv1beta1.Policy_ApprovalStep{
4✔
411
                                Name:                  s.Name,
4✔
412
                                Description:           s.Description,
4✔
413
                                When:                  s.When,
4✔
414
                                Strategy:              string(s.Strategy),
4✔
415
                                RejectionReason:       s.RejectionReason,
4✔
416
                                ApproveIf:             s.ApproveIf,
4✔
417
                                AllowFailed:           s.AllowFailed,
4✔
418
                                Approvers:             s.Approvers,
4✔
419
                                DontAllowSelfApproval: s.DontAllowSelfApproval,
4✔
420
                        })
4✔
421
                }
4✔
422
                policyProto.Steps = steps
4✔
423
        }
424

425
        if p.Requirements != nil {
12✔
426
                var requirements []*guardianv1beta1.Policy_Requirement
4✔
427
                for _, r := range p.Requirements {
8✔
428
                        var on *guardianv1beta1.Policy_Requirement_RequirementTrigger
4✔
429
                        if r.On != nil {
8✔
430
                                var conditions []*guardianv1beta1.Condition
4✔
431
                                if r.On.Conditions != nil {
4✔
432
                                        for _, c := range r.On.Conditions {
×
433
                                                condition, err := a.toConditionProto(c)
×
434
                                                if err != nil {
×
435
                                                        return nil, err
×
436
                                                }
×
437
                                                conditions = append(conditions, condition)
×
438
                                        }
439
                                }
440

441
                                on = &guardianv1beta1.Policy_Requirement_RequirementTrigger{
4✔
442
                                        ProviderType: r.On.ProviderType,
4✔
443
                                        ProviderUrn:  r.On.ProviderURN,
4✔
444
                                        ResourceType: r.On.ResourceType,
4✔
445
                                        ResourceUrn:  r.On.ResourceURN,
4✔
446
                                        Role:         r.On.Role,
4✔
447
                                        Conditions:   conditions,
4✔
448
                                        Expression:   r.On.Expression,
4✔
449
                                }
4✔
450
                        }
451

452
                        var additionalAppeals []*guardianv1beta1.Policy_Requirement_AdditionalAppeal
4✔
453
                        if r.Appeals != nil {
8✔
454
                                for _, aa := range r.Appeals {
8✔
455
                                        var resource *guardianv1beta1.Policy_Requirement_AdditionalAppeal_ResourceIdentifier
4✔
456
                                        if aa.Resource != nil {
8✔
457
                                                resource = &guardianv1beta1.Policy_Requirement_AdditionalAppeal_ResourceIdentifier{
4✔
458
                                                        ProviderType: aa.Resource.ProviderType,
4✔
459
                                                        ProviderUrn:  aa.Resource.ProviderURN,
4✔
460
                                                        Type:         aa.Resource.Type,
4✔
461
                                                        Urn:          aa.Resource.URN,
4✔
462
                                                        Id:           aa.Resource.ID,
4✔
463
                                                }
4✔
464
                                        }
4✔
465

466
                                        additionalAppeals = append(additionalAppeals, &guardianv1beta1.Policy_Requirement_AdditionalAppeal{
4✔
467
                                                Resource: resource,
4✔
468
                                                Role:     aa.Role,
4✔
469
                                                Options:  a.toAppealOptionsProto(aa.Options),
4✔
470
                                                Policy:   a.toPolicyConfigProto(aa.Policy),
4✔
471
                                        })
4✔
472
                                }
473
                        }
474

475
                        requirements = append(requirements, &guardianv1beta1.Policy_Requirement{
4✔
476
                                On:      on,
4✔
477
                                Appeals: additionalAppeals,
4✔
478
                        })
4✔
479
                        policyProto.Requirements = requirements
4✔
480
                }
481
        }
482

483
        if p.HasIAMConfig() {
15✔
484
                config, err := structpb.NewValue(p.IAM.Config)
7✔
485
                if err != nil {
9✔
486
                        return nil, err
2✔
487
                }
2✔
488

489
                policyProto.Iam = &guardianv1beta1.Policy_IAM{
5✔
490
                        Provider: string(p.IAM.Provider),
5✔
491
                        Config:   config,
5✔
492
                        Schema:   p.IAM.Schema,
5✔
493
                }
5✔
494
        }
495

496
        appealConfig, err := a.ToPolicyAppealConfigProto(p)
6✔
497
        if err != nil {
6✔
498
                return nil, fmt.Errorf("failed to convert appeal config to proto: %w", err)
×
499
        }
×
500
        policyProto.Appeal = appealConfig
6✔
501

6✔
502
        if !p.CreatedAt.IsZero() {
10✔
503
                policyProto.CreatedAt = timestamppb.New(p.CreatedAt)
4✔
504
        }
4✔
505
        if !p.UpdatedAt.IsZero() {
10✔
506
                policyProto.UpdatedAt = timestamppb.New(p.UpdatedAt)
4✔
507
        }
4✔
508

509
        return policyProto, nil
6✔
510
}
511

512
func (a *adapter) ToPolicyAppealConfigProto(p *domain.Policy) (*guardianv1beta1.PolicyAppealConfig, error) {
7✔
513
        if p.AppealConfig == nil {
8✔
514
                return nil, nil
1✔
515
        }
1✔
516

517
        policyAppealConfigProto := &guardianv1beta1.PolicyAppealConfig{}
6✔
518
        var durationOptions []*guardianv1beta1.PolicyAppealConfig_DurationOptions
6✔
519
        if p.AppealConfig.DurationOptions != nil {
10✔
520
                for _, d := range p.AppealConfig.DurationOptions {
12✔
521
                        durationOptions = append(durationOptions, &guardianv1beta1.PolicyAppealConfig_DurationOptions{
8✔
522
                                Name:  d.Name,
8✔
523
                                Value: d.Value,
8✔
524
                        })
8✔
525
                }
8✔
526
        }
527
        policyAppealConfigProto.DurationOptions = durationOptions
6✔
528
        policyAppealConfigProto.AllowOnBehalf = p.AppealConfig.AllowOnBehalf
6✔
529
        policyAppealConfigProto.AllowPermanentAccess = p.AppealConfig.AllowPermanentAccess
6✔
530
        policyAppealConfigProto.AllowActiveAccessExtensionIn = p.AppealConfig.AllowActiveAccessExtensionIn
6✔
531
        policyAppealConfigProto.AllowCreatorDetailsFailure = p.AppealConfig.AllowCreatorDetailsFailure
6✔
532

6✔
533
        for _, q := range p.AppealConfig.Questions {
7✔
534
                policyAppealConfigProto.Questions = append(policyAppealConfigProto.Questions, &guardianv1beta1.PolicyAppealConfig_Question{
1✔
535
                        Key:         q.Key,
1✔
536
                        Question:    q.Question,
1✔
537
                        Required:    q.Required,
1✔
538
                        Description: q.Description,
1✔
539
                })
1✔
540
        }
1✔
541

542
        for key, metadataSource := range p.AppealConfig.MetadataSources {
9✔
543
                if policyAppealConfigProto.MetadataSources == nil {
6✔
544
                        policyAppealConfigProto.MetadataSources = make(map[string]*guardianv1beta1.PolicyAppealConfig_MetadataSource)
3✔
545
                }
3✔
546
                policyAppealConfigProto.MetadataSources[key] = &guardianv1beta1.PolicyAppealConfig_MetadataSource{
3✔
547
                        Name:        metadataSource.Name,
3✔
548
                        Description: metadataSource.Description,
3✔
549
                        Type:        metadataSource.Type,
3✔
550
                }
3✔
551

3✔
552
                if metadataSource.Config != nil {
4✔
553
                        cfg, err := structpb.NewValue(metadataSource.Config)
1✔
554
                        if err != nil {
1✔
555
                                return nil, err
×
556
                        }
×
557
                        policyAppealConfigProto.MetadataSources[key].Config = cfg
1✔
558
                }
559
                if metadataSource.Value != nil {
4✔
560
                        value, err := structpb.NewValue(metadataSource.Value)
1✔
561
                        if err != nil {
1✔
562
                                return nil, err
×
563
                        }
×
564
                        policyAppealConfigProto.MetadataSources[key].Value = value
1✔
565
                }
566
        }
567

568
        return policyAppealConfigProto, nil
6✔
569
}
570

571
func (a *adapter) FromResourceProto(r *guardianv1beta1.Resource) *domain.Resource {
4✔
572
        resource := &domain.Resource{
4✔
573
                ID:           r.GetId(),
4✔
574
                ProviderType: r.GetProviderType(),
4✔
575
                ProviderURN:  r.GetProviderUrn(),
4✔
576
                Type:         r.GetType(),
4✔
577
                URN:          r.GetUrn(),
4✔
578
                Name:         r.GetName(),
4✔
579
                Labels:       r.GetLabels(),
4✔
580
                IsDeleted:    r.GetIsDeleted(),
4✔
581
                GroupID:      r.GetGroupId(),
4✔
582
                GroupType:    r.GetGroupType(),
4✔
583
        }
4✔
584

4✔
585
        if r.GetParentId() != "" {
4✔
586
                id := r.GetParentId()
×
587
                resource.ParentID = &id
×
588
        }
×
589

590
        if r.GetChildren() != nil {
4✔
591
                for _, c := range r.GetChildren() {
×
592
                        resource.Children = append(resource.Children, a.FromResourceProto(c))
×
593
                }
×
594
        }
595

596
        if r.GetDetails() != nil {
4✔
597
                resource.Details = r.GetDetails().AsMap()
×
598
        }
×
599

600
        if r.GetCreatedAt() != nil {
4✔
601
                resource.CreatedAt = r.GetCreatedAt().AsTime()
×
602
        }
×
603
        if r.GetUpdatedAt() != nil {
4✔
604
                resource.UpdatedAt = r.GetUpdatedAt().AsTime()
×
605
        }
×
606

607
        return resource
4✔
608
}
609

610
func (a *adapter) ToResourceProto(r *domain.Resource) (*guardianv1beta1.Resource, error) {
26✔
611
        resourceProto := &guardianv1beta1.Resource{
26✔
612
                Id:           r.ID,
26✔
613
                ProviderType: r.ProviderType,
26✔
614
                ProviderUrn:  r.ProviderURN,
26✔
615
                Type:         r.Type,
26✔
616
                Urn:          r.URN,
26✔
617
                Name:         r.Name,
26✔
618
                Labels:       r.Labels,
26✔
619
                IsDeleted:    r.IsDeleted,
26✔
620
                GroupId:      r.GroupID,
26✔
621
                GroupType:    r.GroupType,
26✔
622
        }
26✔
623

26✔
624
        if r.ParentID != nil {
26✔
625
                resourceProto.ParentId = *r.ParentID
×
626
        }
×
627

628
        if r.GlobalURN != "" {
27✔
629
                resourceProto.GlobalUrn = r.GlobalURN
1✔
630
        }
1✔
631

632
        if r.Children != nil {
26✔
633
                for _, c := range r.Children {
×
634
                        childProto, err := a.ToResourceProto(c)
×
635
                        if err != nil {
×
636
                                return nil, fmt.Errorf("failed to convert child resource to proto %q: %w", c.ID, err)
×
637
                        }
×
638
                        resourceProto.Children = append(resourceProto.Children, childProto)
×
639
                }
640
        }
641

642
        if r.Details != nil {
32✔
643
                details, err := structpb.NewStruct(r.Details)
6✔
644
                if err != nil {
11✔
645
                        return nil, err
5✔
646
                }
5✔
647
                resourceProto.Details = details
1✔
648
        }
649

650
        if !r.CreatedAt.IsZero() {
24✔
651
                resourceProto.CreatedAt = timestamppb.New(r.CreatedAt)
3✔
652
        }
3✔
653
        if !r.UpdatedAt.IsZero() {
24✔
654
                resourceProto.UpdatedAt = timestamppb.New(r.UpdatedAt)
3✔
655
        }
3✔
656

657
        return resourceProto, nil
21✔
658
}
659

660
func (a *adapter) ToAppealProto(appeal *domain.Appeal) (*guardianv1beta1.Appeal, error) {
28✔
661
        appealProto := &guardianv1beta1.Appeal{
28✔
662
                Id:            appeal.ID,
28✔
663
                ResourceId:    appeal.ResourceID,
28✔
664
                PolicyId:      appeal.PolicyID,
28✔
665
                PolicyVersion: uint32(appeal.PolicyVersion),
28✔
666
                Status:        appeal.Status,
28✔
667
                AccountId:     appeal.AccountID,
28✔
668
                AccountType:   appeal.AccountType,
28✔
669
                GroupId:       appeal.GroupID,
28✔
670
                GroupType:     appeal.GroupType,
28✔
671
                CreatedBy:     appeal.CreatedBy,
28✔
672
                Role:          appeal.Role,
28✔
673
                Permissions:   appeal.Permissions,
28✔
674
                Options:       a.toAppealOptionsProto(appeal.Options),
28✔
675
                Labels:        appeal.Labels,
28✔
676
                Description:   appeal.Description,
28✔
677
                Revision:      uint32(appeal.Revision),
28✔
678
        }
28✔
679

28✔
680
        if appeal.Resource != nil {
42✔
681
                r, err := a.ToResourceProto(appeal.Resource)
14✔
682
                if err != nil {
14✔
683
                        return nil, err
×
684
                }
×
685
                appealProto.Resource = r
14✔
686
        }
687

688
        if appeal.Creator != nil {
47✔
689
                creator, err := structpb.NewValue(appeal.Creator)
19✔
690
                if err != nil {
29✔
691
                        return nil, err
10✔
692
                }
10✔
693
                appealProto.Creator = creator
9✔
694
        }
695

696
        if appeal.Approvals != nil {
27✔
697
                approvals := []*guardianv1beta1.Approval{}
9✔
698
                for _, approval := range appeal.Approvals {
18✔
699
                        approvalProto, err := a.ToApprovalProto(approval)
9✔
700
                        if err != nil {
9✔
701
                                return nil, err
×
702
                        }
×
703

704
                        approvals = append(approvals, approvalProto)
9✔
705
                }
706
                appealProto.Approvals = approvals
9✔
707
        }
708

709
        if appeal.Details != nil {
30✔
710
                details, err := structpb.NewStruct(appeal.Details)
12✔
711
                if err != nil {
12✔
712
                        return nil, err
×
713
                }
×
714
                appealProto.Details = details
12✔
715
        }
716

717
        if !appeal.CreatedAt.IsZero() {
31✔
718
                appealProto.CreatedAt = timestamppb.New(appeal.CreatedAt)
13✔
719
        }
13✔
720
        if !appeal.UpdatedAt.IsZero() {
31✔
721
                appealProto.UpdatedAt = timestamppb.New(appeal.UpdatedAt)
13✔
722
        }
13✔
723

724
        grantProto, err := a.ToGrantProto(appeal.Grant)
18✔
725
        if err != nil {
18✔
726
                return nil, fmt.Errorf("parsing grant: %w", err)
×
727
        }
×
728
        appealProto.Grant = grantProto
18✔
729

18✔
730
        return appealProto, nil
18✔
731
}
732

733
func (a *adapter) FromCreateAppealProto(ca *guardianv1beta1.CreateAppealRequest, authenticatedUser string) ([]*domain.Appeal, error) {
5✔
734
        var appeals []*domain.Appeal
5✔
735

5✔
736
        for _, r := range ca.GetResources() {
8✔
737
                appeal := &domain.Appeal{
3✔
738
                        AccountID:   ca.GetAccountId(),
3✔
739
                        AccountType: ca.GetAccountType(),
3✔
740
                        GroupID:     r.GetGroupId(),
3✔
741
                        GroupType:   r.GetGroupType(),
3✔
742
                        CreatedBy:   authenticatedUser,
3✔
743
                        ResourceID:  r.GetId(),
3✔
744
                        Role:        r.GetRole(),
3✔
745
                        Description: ca.GetDescription(),
3✔
746
                }
3✔
747

3✔
748
                if r.GetOptions() != nil {
5✔
749
                        var options *domain.AppealOptions
2✔
750
                        if err := mapstructure.Decode(r.GetOptions().AsMap(), &options); err != nil {
2✔
751
                                return nil, err
×
752
                        }
×
753
                        appeal.Options = options
2✔
754
                }
755

756
                if r.GetDetails() != nil {
5✔
757
                        appeal.Details = r.GetDetails().AsMap()
2✔
758
                }
2✔
759

760
                appeals = append(appeals, appeal)
3✔
761
        }
762

763
        return appeals, nil
5✔
764
}
765

766
func (a *adapter) FromPatchAppealProto(ua *guardianv1beta1.PatchAppealRequest, authenticatedUser string) (*domain.Appeal, error) {
2✔
767
        appeal := &domain.Appeal{
2✔
768
                ID:          ua.GetId(),
2✔
769
                AccountID:   ua.GetAccountId(),
2✔
770
                AccountType: ua.GetAccountType(),
2✔
771
                CreatedBy:   authenticatedUser,
2✔
772
                ResourceID:  ua.GetResourceId(),
2✔
773
                Role:        ua.GetRole(),
2✔
774
                Description: ua.GetDescription(),
2✔
775
        }
2✔
776

2✔
777
        if ua.GetOptions() != nil {
3✔
778
                var options *domain.AppealOptions
1✔
779
                if err := mapstructure.Decode(ua.GetOptions().AsMap(), &options); err != nil {
1✔
780
                        return nil, err
×
781
                }
×
782
                appeal.Options = options
1✔
783
        }
784

785
        if ua.GetDetails() != nil {
3✔
786
                appeal.Details = ua.GetDetails().AsMap()
1✔
787
        }
1✔
788

789
        return appeal, nil
2✔
790
}
791

792
func (a *adapter) ToApprovalProto(approval *domain.Approval) (*guardianv1beta1.Approval, error) {
13✔
793
        approvalProto := &guardianv1beta1.Approval{
13✔
794
                Id:             approval.ID,
13✔
795
                Name:           approval.Name,
13✔
796
                AppealId:       approval.AppealID,
13✔
797
                Status:         approval.Status,
13✔
798
                Reason:         approval.Reason,
13✔
799
                PolicyId:       approval.PolicyID,
13✔
800
                PolicyVersion:  uint32(approval.PolicyVersion),
13✔
801
                Approvers:      approval.Approvers,
13✔
802
                CreatedAt:      timestamppb.New(approval.CreatedAt),
13✔
803
                UpdatedAt:      timestamppb.New(approval.UpdatedAt),
13✔
804
                IsStale:        approval.IsStale,
13✔
805
                AppealRevision: uint32(approval.AppealRevision),
13✔
806
        }
13✔
807

13✔
808
        if approval.Appeal != nil {
17✔
809
                appeal, err := a.ToAppealProto(approval.Appeal)
4✔
810
                if err != nil {
6✔
811
                        return nil, err
2✔
812
                }
2✔
813
                approvalProto.Appeal = appeal
2✔
814
        }
815

816
        if approval.Actor != nil {
12✔
817
                approvalProto.Actor = *approval.Actor
1✔
818
        }
1✔
819

820
        if !approval.CreatedAt.IsZero() {
22✔
821
                approvalProto.CreatedAt = timestamppb.New(approval.CreatedAt)
11✔
822
        }
11✔
823
        if !approval.UpdatedAt.IsZero() {
22✔
824
                approvalProto.UpdatedAt = timestamppb.New(approval.UpdatedAt)
11✔
825
        }
11✔
826

827
        return approvalProto, nil
11✔
828
}
829

830
func (a *adapter) FromGrantProto(g *guardianv1beta1.Grant) *domain.Grant {
×
831
        if g == nil {
×
832
                return nil
×
833
        }
×
834

835
        grant := &domain.Grant{
×
836
                ID:                   g.GetId(),
×
837
                Status:               domain.GrantStatus(g.GetStatus()),
×
838
                StatusInProvider:     domain.GrantStatus(g.GetStatusInProvider()),
×
839
                AccountID:            g.GetAccountId(),
×
840
                AccountType:          g.GetAccountType(),
×
841
                GroupID:              g.GetGroupId(),
×
842
                GroupType:            g.GetGroupType(),
×
843
                ResourceID:           g.GetResourceId(),
×
844
                Role:                 g.GetRole(),
×
845
                Permissions:          g.GetPermissions(),
×
846
                AppealID:             g.GetAppealId(),
×
847
                Source:               domain.GrantSource(g.Source),
×
848
                RevokedBy:            g.GetRevokedBy(),
×
849
                RevokeReason:         g.GetRevokeReason(),
×
850
                CreatedBy:            g.GetCreatedBy(),
×
851
                Owner:                g.GetOwner(),
×
852
                Resource:             a.FromResourceProto(g.GetResource()),
×
853
                ExpirationDateReason: g.GetExpirationDateReason(),
×
854
                RestoreReason:        g.GetRestoreReason(),
×
855
                RestoredBy:           g.GetRestoredBy(),
×
856
        }
×
857

×
858
        if g.GetExpirationDate() != nil {
×
859
                t := g.GetExpirationDate().AsTime()
×
860
                grant.ExpirationDate = &t
×
861
        }
×
862
        if g.GetRevokedAt() != nil {
×
863
                t := g.GetRevokedAt().AsTime()
×
864
                grant.RevokedAt = &t
×
865
        }
×
866
        if g.GetCreatedAt() != nil {
×
867
                grant.CreatedAt = g.GetCreatedAt().AsTime()
×
868
        }
×
869
        if g.GetUpdatedAt() != nil {
×
870
                grant.UpdatedAt = g.GetUpdatedAt().AsTime()
×
871
        }
×
872
        if g.GetRestoredAt() != nil {
×
873
                t := g.GetRestoredAt().AsTime()
×
874
                grant.RestoredAt = &t
×
875
        }
×
876

877
        return grant
×
878
}
879

880
func (a *adapter) ToGrantProto(grant *domain.Grant) (*guardianv1beta1.Grant, error) {
27✔
881
        if grant == nil {
45✔
882
                return nil, nil
18✔
883
        }
18✔
884

885
        grantProto := &guardianv1beta1.Grant{
9✔
886
                Id:                   grant.ID,
9✔
887
                Status:               string(grant.Status),
9✔
888
                StatusInProvider:     string(grant.StatusInProvider),
9✔
889
                AccountId:            grant.AccountID,
9✔
890
                AccountType:          grant.AccountType,
9✔
891
                GroupId:              grant.GroupID,
9✔
892
                GroupType:            grant.GroupType,
9✔
893
                ResourceId:           grant.ResourceID,
9✔
894
                Role:                 grant.Role,
9✔
895
                Permissions:          grant.Permissions,
9✔
896
                IsPermanent:          grant.IsPermanent,
9✔
897
                AppealId:             grant.AppealID,
9✔
898
                Source:               string(grant.Source),
9✔
899
                RevokedBy:            grant.RevokedBy,
9✔
900
                RevokeReason:         grant.RevokeReason,
9✔
901
                CreatedBy:            grant.CreatedBy,
9✔
902
                Owner:                grant.Owner,
9✔
903
                ExpirationDateReason: grant.ExpirationDateReason,
9✔
904
                RestoreReason:        grant.RestoreReason,
9✔
905
                RestoredBy:           grant.RestoredBy,
9✔
906
        }
9✔
907

9✔
908
        if grant.ExpirationDate != nil {
13✔
909
                grantProto.ExpirationDate = timestamppb.New(*grant.ExpirationDate)
4✔
910
        }
4✔
911
        if grant.RevokedAt != nil {
12✔
912
                grantProto.RevokedAt = timestamppb.New(*grant.RevokedAt)
3✔
913
        }
3✔
914
        if !grant.CreatedAt.IsZero() {
13✔
915
                grantProto.CreatedAt = timestamppb.New(grant.CreatedAt)
4✔
916
        }
4✔
917
        if !grant.UpdatedAt.IsZero() {
16✔
918
                grantProto.UpdatedAt = timestamppb.New(grant.UpdatedAt)
7✔
919
        }
7✔
920
        if grant.Resource != nil {
15✔
921
                resourceProto, err := a.ToResourceProto(grant.Resource)
6✔
922
                if err != nil {
8✔
923
                        return nil, fmt.Errorf("parsing resource: %w", err)
2✔
924
                }
2✔
925
                grantProto.Resource = resourceProto
4✔
926
        }
927
        if grant.Appeal != nil {
11✔
928
                appealProto, err := a.ToAppealProto(grant.Appeal)
4✔
929
                if err != nil {
4✔
930
                        return nil, fmt.Errorf("parsing appeal: %w", err)
×
931
                }
×
932
                grantProto.Appeal = appealProto
4✔
933
        }
934
        if grant.RestoredAt != nil {
7✔
935
                grantProto.RestoredAt = timestamppb.New(*grant.RestoredAt)
×
936
        }
×
937

938
        return grantProto, nil
7✔
939
}
940

941
func (a *adapter) FromUpdateGrantRequestProto(grantUpdate *guardianv1beta1.UpdateGrantRequest) *domain.GrantUpdate {
4✔
942
        if grantUpdate == nil {
4✔
943
                return nil
×
944
        }
×
945

946
        gu := &domain.GrantUpdate{
4✔
947
                ID:                   grantUpdate.GetId(),
4✔
948
                ExpirationDateReason: grantUpdate.ExpirationDateReason,
4✔
949
        }
4✔
950
        if grantUpdate.GetOwner() != "" {
8✔
951
                gu.Owner = &grantUpdate.Owner
4✔
952
        }
4✔
953

954
        if grantUpdate.ExpirationDate != nil {
4✔
955
                expDate := grantUpdate.GetExpirationDate().AsTime()
×
956
                gu.ExpirationDate = &expDate
×
957
        }
×
958

959
        return gu
4✔
960
}
961

962
func (a *adapter) ToActivityProto(activity *domain.Activity) (*guardianv1beta1.ProviderActivity, error) {
×
963
        if activity == nil {
×
964
                return nil, nil
×
965
        }
×
966

967
        activityProto := &guardianv1beta1.ProviderActivity{
×
968
                Id:                 activity.ID,
×
969
                ProviderId:         activity.ProviderID,
×
970
                ResourceId:         activity.ResourceID,
×
971
                ProviderActivityId: activity.ProviderActivityID,
×
972
                AccountType:        activity.AccountType,
×
973
                AccountId:          activity.AccountID,
×
974
                Authorizations:     activity.Authorizations,
×
975
                RelatedPermissions: activity.RelatedPermissions,
×
976
                Type:               activity.Type,
×
977
        }
×
978

×
979
        if !activity.Timestamp.IsZero() {
×
980
                activityProto.Timestamp = timestamppb.New(activity.Timestamp)
×
981
        }
×
982

983
        if activity.Metadata != nil {
×
984
                metadataStruct, err := structpb.NewStruct(activity.Metadata)
×
985
                if err != nil {
×
986
                        return nil, fmt.Errorf("parsing metadata: %w", err)
×
987
                }
×
988
                activityProto.Metadata = metadataStruct
×
989
        }
990

991
        if !activity.CreatedAt.IsZero() {
×
992
                activityProto.CreatedAt = timestamppb.New(activity.CreatedAt)
×
993
        }
×
994

995
        if activity.Provider != nil {
×
996
                providerProto, err := a.ToProviderProto(activity.Provider)
×
997
                if err != nil {
×
998
                        return nil, fmt.Errorf("parsing provider: %w", err)
×
999
                }
×
1000
                activityProto.Provider = providerProto
×
1001
        }
1002

1003
        if activity.Resource != nil {
×
1004
                resourceProto, err := a.ToResourceProto(activity.Resource)
×
1005
                if err != nil {
×
1006
                        return nil, fmt.Errorf("parsing resource: %w", err)
×
1007
                }
×
1008
                activityProto.Resource = resourceProto
×
1009
        }
1010

1011
        return activityProto, nil
×
1012
}
1013

1014
func (a *adapter) ToCommentProto(c *domain.Comment) *guardianv1beta1.AppealComment {
3✔
1015
        if c == nil {
3✔
1016
                return nil
×
1017
        }
×
1018

1019
        commentProto := &guardianv1beta1.AppealComment{
3✔
1020
                Id:        c.ID,
3✔
1021
                AppealId:  c.ParentID,
3✔
1022
                CreatedBy: c.CreatedBy,
3✔
1023
                Body:      c.Body,
3✔
1024
        }
3✔
1025

3✔
1026
        if !c.CreatedAt.IsZero() {
6✔
1027
                commentProto.CreatedAt = timestamppb.New(c.CreatedAt)
3✔
1028
        }
3✔
1029
        if !c.UpdatedAt.IsZero() {
6✔
1030
                commentProto.UpdatedAt = timestamppb.New(c.UpdatedAt)
3✔
1031
        }
3✔
1032

1033
        return commentProto
3✔
1034
}
1035

1036
func (a *adapter) fromConditionProto(c *guardianv1beta1.Condition) *domain.Condition {
×
1037
        if c == nil {
×
1038
                return nil
×
1039
        }
×
1040

1041
        var match *domain.MatchCondition
×
1042
        if c.GetMatch() != nil {
×
1043
                match = &domain.MatchCondition{
×
1044
                        Eq: c.GetMatch().GetEq(),
×
1045
                }
×
1046
        }
×
1047

1048
        return &domain.Condition{
×
1049
                Field: c.GetField(),
×
1050
                Match: match,
×
1051
        }
×
1052
}
1053

1054
func (a *adapter) ToAppealActivityProto(e *domain.Event) (*guardianv1beta1.AppealActivity, error) {
×
1055
        if e == nil {
×
1056
                return nil, nil
×
1057
        }
×
1058

1059
        activityProto := &guardianv1beta1.AppealActivity{
×
1060
                AppealId:  e.ParentID,
×
1061
                Timestamp: timestamppb.New(e.Timestamp),
×
1062
                Type:      e.Type,
×
1063
                Actor:     e.Actor,
×
1064
        }
×
1065

×
1066
        if e.Data != nil {
×
1067
                data, err := structpb.NewStruct(e.Data)
×
1068
                if err != nil {
×
1069
                        return nil, err
×
1070
                }
×
1071
                activityProto.Data = data
×
1072
        }
1073
        return activityProto, nil
×
1074
}
1075

1076
func (a *adapter) ToSummaryProto(s *domain.SummaryResult) (*guardianv1beta1.SummaryResult, error) {
×
1077
        if s == nil {
×
1078
                return nil, nil
×
1079
        }
×
1080

1081
        var appliedParameters *guardianv1beta1.SummaryParameters
×
1082
        if s.AppliedParameters != nil {
×
1083
                filters, err := toProtoMap(s.AppliedParameters.Filters)
×
1084
                if err != nil {
×
1085
                        return nil, fmt.Errorf("parsing filters: %w", err)
×
1086
                }
×
1087

1088
                appliedParameters = &guardianv1beta1.SummaryParameters{
×
1089
                        GroupBys: s.AppliedParameters.GroupBys,
×
1090
                        Filters:  filters,
×
1091
                }
×
1092
        }
1093

1094
        summaryProto := &guardianv1beta1.SummaryResult{
×
1095
                AppliedParameters: appliedParameters,
×
1096
                Groups:            make([]*guardianv1beta1.SummaryResult_Group, len(s.SummaryGroups)),
×
1097
                Count:             s.Count,
×
1098
        }
×
1099

×
1100
        for i, group := range s.SummaryGroups {
×
1101
                groupFields, err := toProtoMap(group.GroupFields)
×
1102
                if err != nil {
×
1103
                        return nil, fmt.Errorf("parsing group fields: %w", err)
×
1104
                }
×
1105

1106
                summaryProto.Groups[i] = &guardianv1beta1.SummaryResult_Group{
×
1107
                        GroupFields: groupFields,
×
1108
                        Count:       group.Count,
×
1109
                }
×
1110
        }
1111

1112
        return summaryProto, nil
×
1113
}
1114

1115
func (a *adapter) toConditionProto(c *domain.Condition) (*guardianv1beta1.Condition, error) {
×
1116
        if c == nil {
×
1117
                return nil, nil
×
1118
        }
×
1119

1120
        var match *guardianv1beta1.Condition_MatchCondition
×
1121
        if c.Match != nil {
×
1122
                eq, err := structpb.NewValue(c.Match.Eq)
×
1123
                if err != nil {
×
1124
                        return nil, err
×
1125
                }
×
1126

1127
                match = &guardianv1beta1.Condition_MatchCondition{
×
1128
                        Eq: eq,
×
1129
                }
×
1130
        }
1131

1132
        return &guardianv1beta1.Condition{
×
1133
                Field: c.Field,
×
1134
                Match: match,
×
1135
        }, nil
×
1136
}
1137

1138
func (a *adapter) fromAppealOptionsProto(o *guardianv1beta1.AppealOptions) *domain.AppealOptions {
2✔
1139
        if o == nil {
3✔
1140
                return nil
1✔
1141
        }
1✔
1142

1143
        options := &domain.AppealOptions{
1✔
1144
                Duration: o.GetDuration(),
1✔
1145
        }
1✔
1146

1✔
1147
        if o.GetExpirationDate() != nil {
1✔
1148
                expDate := o.GetExpirationDate().AsTime()
×
1149
                options.ExpirationDate = &expDate
×
1150
        }
×
1151

1152
        return options
1✔
1153
}
1154

1155
func (a *adapter) toAppealOptionsProto(o *domain.AppealOptions) *guardianv1beta1.AppealOptions {
32✔
1156
        if o == nil {
49✔
1157
                return nil
17✔
1158
        }
17✔
1159

1160
        optionsProto := &guardianv1beta1.AppealOptions{
15✔
1161
                Duration: o.Duration,
15✔
1162
        }
15✔
1163

15✔
1164
        if o.ExpirationDate != nil {
26✔
1165
                optionsProto.ExpirationDate = timestamppb.New(*o.ExpirationDate)
11✔
1166
        }
11✔
1167

1168
        return optionsProto
15✔
1169
}
1170

1171
func (a *adapter) fromPolicyConfigProto(c *guardianv1beta1.PolicyConfig) *domain.PolicyConfig {
4✔
1172
        if c == nil {
4✔
1173
                return nil
×
1174
        }
×
1175

1176
        return &domain.PolicyConfig{
4✔
1177
                ID:      c.GetId(),
4✔
1178
                Version: int(c.GetVersion()),
4✔
1179
        }
4✔
1180
}
1181

1182
func (a *adapter) toPolicyConfigProto(c *domain.PolicyConfig) *guardianv1beta1.PolicyConfig {
8✔
1183
        if c == nil {
8✔
1184
                return nil
×
1185
        }
×
1186

1187
        return &guardianv1beta1.PolicyConfig{
8✔
1188
                Id:      c.ID,
8✔
1189
                Version: int32(c.Version),
8✔
1190
        }
8✔
1191
}
1192

1193
func toGoMap(in map[string]*structpb.Value) map[string]any {
×
1194
        out := make(map[string]any, len(in))
×
1195
        for k, v := range in {
×
1196
                out[k] = v.AsInterface()
×
1197
        }
×
1198
        return out
×
1199
}
1200

1201
func toProtoMap(in map[string]any) (map[string]*structpb.Value, error) {
×
1202
        out := make(map[string]*structpb.Value, len(in))
×
1203
        for k, v := range in {
×
1204
                val, err := structpb.NewValue(v)
×
1205
                if err != nil {
×
1206
                        return nil, err
×
1207
                }
×
1208
                out[k] = val
×
1209
        }
1210
        return out, nil
×
1211
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc