Skip to content

Commit 1287d2c

Browse files
authored
Merge pull request #125 from kubescape/bump-armoapi
bump armoapi version to 207
2 parents 04dd5f1 + e2b6da7 commit 1287d2c

7 files changed

Lines changed: 62 additions & 55 deletions

File tree

exceptions/designators_cache.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package exceptions
22

33
import (
4+
"github.com/armosec/armoapi-go/identifiers"
45
"sync"
56

6-
"github.com/armosec/armoapi-go/armotypes"
77
"github.com/kubescape/opa-utils/exceptions/internal/hashmap"
88
)
99

@@ -14,11 +14,11 @@ type (
1414
// a few slots for designators.
1515
designatorCache struct {
1616
mx sync.RWMutex
17-
innerMap map[portalDesignatorKey]armotypes.AttributesDesignators
17+
innerMap map[portalDesignatorKey]identifiers.AttributesDesignators
1818
}
1919

2020
portalDesignatorKey struct {
21-
DesignatorType armotypes.DesignatorType
21+
DesignatorType identifiers.DesignatorType
2222
WLID string
2323
WildWLID string
2424
SID string
@@ -37,11 +37,11 @@ func newDesignatorCache() *designatorCache {
3737
const heuristicAllocDesignators = 1000 // this is a hint on the number of AttributeDesignators to hold, in order to minimize dynamic reallocations for this map
3838

3939
return &designatorCache{
40-
innerMap: make(map[portalDesignatorKey]armotypes.AttributesDesignators, heuristicAllocDesignators),
40+
innerMap: make(map[portalDesignatorKey]identifiers.AttributesDesignators, heuristicAllocDesignators),
4141
}
4242
}
4343

44-
func (c *designatorCache) Get(designator *armotypes.PortalDesignator) (armotypes.AttributesDesignators, bool) {
44+
func (c *designatorCache) Get(designator *identifiers.PortalDesignator) (identifiers.AttributesDesignators, bool) {
4545
key := c.toDesignatorKey(designator)
4646

4747
c.mx.RLock()
@@ -52,7 +52,7 @@ func (c *designatorCache) Get(designator *armotypes.PortalDesignator) (armotypes
5252
return val, ok
5353
}
5454

55-
func (c *designatorCache) Set(designator *armotypes.PortalDesignator, value armotypes.AttributesDesignators) {
55+
func (c *designatorCache) Set(designator *identifiers.PortalDesignator, value identifiers.AttributesDesignators) {
5656
key := c.toDesignatorKey(designator)
5757

5858
c.mx.Lock()
@@ -61,7 +61,7 @@ func (c *designatorCache) Set(designator *armotypes.PortalDesignator, value armo
6161
c.innerMap[key] = value
6262
}
6363

64-
func (c *designatorCache) toDesignatorKey(designator *armotypes.PortalDesignator) portalDesignatorKey {
64+
func (c *designatorCache) toDesignatorKey(designator *identifiers.PortalDesignator) portalDesignatorKey {
6565
return portalDesignatorKey{
6666
DesignatorType: designator.DesignatorType,
6767
WLID: designator.WLID,

exceptions/designators_cache_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package exceptions
22

33
import (
4+
"github.com/armosec/armoapi-go/identifiers"
45
"testing"
56

6-
"github.com/armosec/armoapi-go/armotypes"
77
"github.com/stretchr/testify/require"
88
)
99

1010
func TestDesignatorsCache(t *testing.T) {
1111
cache := &designatorCache{
12-
innerMap: make(map[portalDesignatorKey]armotypes.AttributesDesignators, 1000),
12+
innerMap: make(map[portalDesignatorKey]identifiers.AttributesDesignators, 1000),
1313
// seed: maphash.MakeSeed(), // for maphash version
1414
}
1515

1616
t.Run("should retrieve cached designator", func(t *testing.T) {
17-
designator := &armotypes.PortalDesignator{
18-
DesignatorType: armotypes.DesignatorAttributes,
17+
designator := &identifiers.PortalDesignator{
18+
DesignatorType: identifiers.DesignatorAttributes,
1919
WLID: "x",
2020
WildWLID: "y",
2121
SID: "z",
@@ -38,8 +38,8 @@ func TestDesignatorsCache(t *testing.T) {
3838
})
3939

4040
t.Run("should not collide with previously cached designator (WLID differs)", func(t *testing.T) {
41-
designator := &armotypes.PortalDesignator{
42-
DesignatorType: armotypes.DesignatorAttributes,
41+
designator := &identifiers.PortalDesignator{
42+
DesignatorType: identifiers.DesignatorAttributes,
4343
WLID: "x1",
4444
WildWLID: "y",
4545
SID: "z",
@@ -62,8 +62,8 @@ func TestDesignatorsCache(t *testing.T) {
6262
})
6363

6464
t.Run("should not collide with previously cached designator (attributes differ)", func(t *testing.T) {
65-
designator := &armotypes.PortalDesignator{
66-
DesignatorType: armotypes.DesignatorAttributes,
65+
designator := &identifiers.PortalDesignator{
66+
DesignatorType: identifiers.DesignatorAttributes,
6767
WLID: "x",
6868
WildWLID: "y",
6969
SID: "z",
@@ -87,8 +87,8 @@ func TestDesignatorsCache(t *testing.T) {
8787
})
8888

8989
t.Run("should support empty attributes", func(t *testing.T) {
90-
designator := &armotypes.PortalDesignator{
91-
DesignatorType: armotypes.DesignatorAttributes,
90+
designator := &identifiers.PortalDesignator{
91+
DesignatorType: identifiers.DesignatorAttributes,
9292
WLID: "x",
9393
WildWLID: "y",
9494
SID: "z",
@@ -109,11 +109,11 @@ func TestDesignatorsCache(t *testing.T) {
109109

110110
func BenchmarkDesignatorsCache(b *testing.B) {
111111
cache := &designatorCache{
112-
innerMap: make(map[portalDesignatorKey]armotypes.AttributesDesignators, 1000),
112+
innerMap: make(map[portalDesignatorKey]identifiers.AttributesDesignators, 1000),
113113
}
114114

115-
designator := &armotypes.PortalDesignator{
116-
DesignatorType: armotypes.DesignatorAttributes,
115+
designator := &identifiers.PortalDesignator{
116+
DesignatorType: identifiers.DesignatorAttributes,
117117
WLID: "x",
118118
WildWLID: "y",
119119
SID: "z",

exceptions/exceptionprocessor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package exceptions
22

33
import (
4+
"github.com/armosec/armoapi-go/identifiers"
45
"strings"
56

67
"github.com/kubescape/k8s-interface/workloadinterface"
@@ -153,8 +154,8 @@ func (p *Processor) GetResourceExceptions(ruleExceptions []armotypes.PostureExce
153154
}
154155

155156
// compareMetadata - compare namespace and kind
156-
func (p *Processor) hasException(clusterName string, designator *armotypes.PortalDesignator, workload workloadinterface.IMetadata) bool {
157-
var attributes armotypes.AttributesDesignators
157+
func (p *Processor) hasException(clusterName string, designator *identifiers.PortalDesignator, workload workloadinterface.IMetadata) bool {
158+
var attributes identifiers.AttributesDesignators
158159
if attrs, ok := p.designatorCache.Get(designator); ok {
159160
attributes = attrs
160161
} else {

exceptions/exceptionprocessor_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package exceptions
22

33
import (
4+
"github.com/armosec/armoapi-go/identifiers"
45
"testing"
56

67
"github.com/kubescape/k8s-interface/workloadinterface"
@@ -23,12 +24,12 @@ func postureExceptionPolicyAlertOnlyMock() *armotypes.PostureExceptionPolicy {
2324
},
2425
PolicyType: "postureExceptionPolicy",
2526
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
26-
Resources: []armotypes.PortalDesignator{
27+
Resources: []identifiers.PortalDesignator{
2728
{
28-
DesignatorType: armotypes.DesignatorAttributes,
29+
DesignatorType: identifiers.DesignatorAttributes,
2930
Attributes: map[string]string{
30-
armotypes.AttributeNamespace: "default",
31-
armotypes.AttributeCluster: "unittest",
31+
identifiers.AttributeNamespace: "default",
32+
identifiers.AttributeCluster: "unittest",
3233
},
3334
},
3435
},
@@ -47,9 +48,9 @@ func postureLabelsRegexExceptionPolicyAlertOnlyMock() *armotypes.PostureExceptio
4748
},
4849
PolicyType: "postureExceptionPolicy",
4950
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
50-
Resources: []armotypes.PortalDesignator{
51+
Resources: []identifiers.PortalDesignator{
5152
{
52-
DesignatorType: armotypes.DesignatorAttributes,
53+
DesignatorType: identifiers.DesignatorAttributes,
5354
Attributes: map[string]string{
5455
"myLabelOrAnnotation": "static_test",
5556
},
@@ -70,12 +71,12 @@ func postureResourceIDExceptionPolicyMock(resourceID string) *armotypes.PostureE
7071
},
7172
PolicyType: "postureExceptionPolicy",
7273
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
73-
Resources: []armotypes.PortalDesignator{
74+
Resources: []identifiers.PortalDesignator{
7475
{
75-
DesignatorType: armotypes.DesignatorAttributes,
76+
DesignatorType: identifiers.DesignatorAttributes,
7677
Attributes: map[string]string{
77-
armotypes.AttributeCluster: "test",
78-
armotypes.AttributeResourceID: resourceID,
78+
identifiers.AttributeCluster: "test",
79+
identifiers.AttributeResourceID: resourceID,
7980
},
8081
},
8182
},
@@ -94,9 +95,9 @@ func emptyPostureExceptionPolicyAlertOnlyMock() *armotypes.PostureExceptionPolic
9495
},
9596
PolicyType: "postureExceptionPolicy",
9697
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
97-
Resources: []armotypes.PortalDesignator{
98+
Resources: []identifiers.PortalDesignator{
9899
{
99-
DesignatorType: armotypes.DesignatorAttributes,
100+
DesignatorType: identifiers.DesignatorAttributes,
100101
Attributes: map[string]string{},
101102
},
102103
},

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/kubescape/opa-utils
33
go 1.19
44

55
require (
6-
github.com/armosec/armoapi-go v0.0.173
6+
github.com/armosec/armoapi-go v0.0.207
77
github.com/armosec/utils-go v0.0.12
88
github.com/francoispqt/gojay v1.2.13
99
github.com/kubescape/k8s-interface v0.0.99
@@ -12,7 +12,7 @@ require (
1212
github.com/open-policy-agent/opa v0.42.0
1313
github.com/stretchr/testify v1.8.3
1414
go.uber.org/zap v1.22.0
15-
golang.org/x/exp v0.0.0-20230519143937-03e91628a987
15+
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22
1616
k8s.io/api v0.25.3
1717
k8s.io/apimachinery v0.25.3
1818
k8s.io/client-go v0.25.3
@@ -35,6 +35,7 @@ require (
3535
github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect
3636
github.com/OneOfOne/xxhash v1.2.8 // indirect
3737
github.com/agnivade/levenshtein v1.0.1 // indirect
38+
github.com/armosec/gojay v1.2.15 // indirect
3839
github.com/armosec/utils-k8s-go v0.0.12 // indirect
3940
github.com/aws/aws-sdk-go-v2 v1.17.3 // indirect
4041
github.com/aws/aws-sdk-go-v2/config v1.15.13 // indirect
@@ -101,7 +102,7 @@ require (
101102
go.opencensus.io v0.23.0 // indirect
102103
go.uber.org/atomic v1.7.0 // indirect
103104
go.uber.org/multierr v1.6.0 // indirect
104-
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
105+
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
105106
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
106107
golang.org/x/oauth2 v0.0.0-20220630143837-2104d58473e0 // indirect
107108
golang.org/x/sys v0.3.0 // indirect

go.sum

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
164164
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
165165
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
166166
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
167-
github.com/armosec/armoapi-go v0.0.173 h1:TwNxmTxx9ATJPZBlld/53s/WvSVUfoF4gxgHT6UbFng=
168-
github.com/armosec/armoapi-go v0.0.173/go.mod h1:xlW8dGq0vVzbuk+kDZqMQIkfU9P/iiiiDavoCIboqgI=
167+
github.com/armosec/armoapi-go v0.0.207 h1:xiayQ5w/odmMWuVXFhiqU6NQP5sXqZ6zwenc+Z+Z430=
168+
github.com/armosec/armoapi-go v0.0.207/go.mod h1:MSaFIxFu2ucjrY2RAzgasZbBlop+S7bNgRz5Q7iOmOc=
169+
github.com/armosec/gojay v1.2.15 h1:sSB2vnAvacUNkw9nzUYZKcPzhJOyk6/5LK2JCNdmoZY=
170+
github.com/armosec/gojay v1.2.15/go.mod h1:vzVAaay2TWJAngOpxu8aqLbye9jMgoKleuAOK+xsOts=
169171
github.com/armosec/utils-go v0.0.12 h1:NXkG/BhbSVAmTVXr0qqsK02CmxEiXuJyPmdTRcZ4jAo=
170172
github.com/armosec/utils-go v0.0.12/go.mod h1:F/K1mI/qcj7fNuJl7xktoCeHM83azOF0Zq6eC2WuPyU=
171173
github.com/armosec/utils-k8s-go v0.0.12 h1:u7kHSUp4PpvPP3hEaRXMbM0Vw23IyLhAzzE+2TW6Jkk=
@@ -1231,8 +1233,9 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
12311233
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
12321234
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
12331235
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
1234-
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
12351236
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
1237+
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b h1:huxqepDufQpLLIRXiVkTvnxrzJlpwmIWAObmcCcUFr0=
1238+
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
12361239
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
12371240
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
12381241
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -1243,8 +1246,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
12431246
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
12441247
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
12451248
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
1246-
golang.org/x/exp v0.0.0-20230519143937-03e91628a987 h1:3xJIFvzUFbu4ls0BTBYcgbCGhA63eAOEMxIHugyXJqA=
1247-
golang.org/x/exp v0.0.0-20230519143937-03e91628a987/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
1249+
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22 h1:FqrVOBQxQ8r/UwwXibI0KMolVhvFiGobSfdE33deHJM=
1250+
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
12481251
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
12491252
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
12501253
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

reporthandling/results/v1/resourcesresults/exceptions_test.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package resourcesresults
22

33
import (
4+
"github.com/armosec/armoapi-go/identifiers"
45
"testing"
56

67
"github.com/armosec/armoapi-go/armotypes"
@@ -16,11 +17,11 @@ func mockExceptionDeploymentC0087() *armotypes.PostureExceptionPolicy {
1617
Name: "DeploymentC0087",
1718
},
1819
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
19-
Resources: []armotypes.PortalDesignator{
20+
Resources: []identifiers.PortalDesignator{
2021
{
21-
DesignatorType: armotypes.DesignatorAttributes,
22+
DesignatorType: identifiers.DesignatorAttributes,
2223
Attributes: map[string]string{
23-
armotypes.AttributeKind: "Deployment",
24+
identifiers.AttributeKind: "Deployment",
2425
},
2526
},
2627
},
@@ -38,12 +39,12 @@ func mockExceptionUnitestDeploymentC0087() *armotypes.PostureExceptionPolicy {
3839
Name: "unitestDeploymentC0087",
3940
},
4041
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
41-
Resources: []armotypes.PortalDesignator{
42+
Resources: []identifiers.PortalDesignator{
4243
{
43-
DesignatorType: armotypes.DesignatorAttributes,
44+
DesignatorType: identifiers.DesignatorAttributes,
4445
Attributes: map[string]string{
45-
armotypes.AttributeCluster: "unitest",
46-
armotypes.AttributeKind: "Deployment",
46+
identifiers.AttributeCluster: "unitest",
47+
identifiers.AttributeKind: "Deployment",
4748
},
4849
},
4950
},
@@ -61,11 +62,11 @@ func mockExceptionUnitestC0088() *armotypes.PostureExceptionPolicy {
6162
Name: "unitestC0088",
6263
},
6364
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
64-
Resources: []armotypes.PortalDesignator{
65+
Resources: []identifiers.PortalDesignator{
6566
{
66-
DesignatorType: armotypes.DesignatorAttributes,
67+
DesignatorType: identifiers.DesignatorAttributes,
6768
Attributes: map[string]string{
68-
armotypes.AttributeCluster: "unitest",
69+
identifiers.AttributeCluster: "unitest",
6970
},
7071
},
7172
},
@@ -83,11 +84,11 @@ func mockExceptionDeploymentC0089() *armotypes.PostureExceptionPolicy {
8384
Name: "Deployment0089",
8485
},
8586
Actions: []armotypes.PostureExceptionPolicyActions{armotypes.AlertOnly},
86-
Resources: []armotypes.PortalDesignator{
87+
Resources: []identifiers.PortalDesignator{
8788
{
88-
DesignatorType: armotypes.DesignatorAttributes,
89+
DesignatorType: identifiers.DesignatorAttributes,
8990
Attributes: map[string]string{
90-
armotypes.AttributeKind: "Deployment",
91+
identifiers.AttributeKind: "Deployment",
9192
},
9293
},
9394
},

0 commit comments

Comments
 (0)