-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathactivity.go
76 lines (64 loc) · 2.27 KB
/
activity.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package domain
import (
"errors"
"time"
)
type Activity struct {
ID string `json:"id" yaml:"id"`
ProviderID string `json:"provider_id" yaml:"provider_id"`
ResourceID string `json:"resource_id" yaml:"resource_id"`
ProviderActivityID string `json:"provider_activity_id" yaml:"provider_activity_id"`
AccountType string `json:"account_type" yaml:"account_type"`
AccountID string `json:"account_id" yaml:"account_id"`
Timestamp time.Time `json:"timestamp" yaml:"timestamp"`
Authorizations []string `json:"authorizations" yaml:"authorizations"`
RelatedPermissions []string `json:"related_permissions" yaml:"related_permissions"`
Type string `json:"type" yaml:"type"`
Metadata map[string]interface{} `json:"metadata" yaml:"metadata"`
CreatedAt time.Time `json:"created_at" yaml:"created_at"`
Provider *Provider `json:"provider,omitempty" yaml:"provider,omitempty"`
Resource *Resource `json:"resource,omitempty" yaml:"resource,omitempty"`
}
type ListProviderActivitiesFilter struct {
ProviderIDs []string
ResourceIDs []string
AccountIDs []string
Types []string
TimestampGte *time.Time
TimestampLte *time.Time
}
type ImportActivitiesFilter struct {
ProviderID string
ResourceIDs []string
AccountIDs []string
TimestampGte *time.Time
TimestampLte *time.Time
resources map[string]*Resource
}
func (f *ImportActivitiesFilter) PopulateResources(resources map[string]*Resource) error {
if f.ResourceIDs == nil {
return nil
}
if resources == nil {
return errors.New("resources cannot be nil")
}
f.resources = make(map[string]*Resource, len(f.ResourceIDs))
for _, resourceID := range f.ResourceIDs {
resource, ok := resources[resourceID]
if !ok {
return errors.New("resource not found")
}
f.resources[resourceID] = resource
}
return nil
}
func (f *ImportActivitiesFilter) GetResources() []*Resource {
if f.resources == nil {
return nil
}
resources := make([]*Resource, 0, len(f.resources))
for _, resource := range f.resources {
resources = append(resources, resource)
}
return resources
}