Skip to content

Commit b73ea17

Browse files
authored
🐛 fetching VPC endpoint services (#5336)
* 🐛 fetching VPC endpoint services This change uses the API `DescribeVpcEndpoints()` to fetch information about endpoint services and delays loading of additional data for when it is accessed. Fixes #5318 Signed-off-by: Salim Afiune Maya <afiune@mondoo.com> * 🐛 service endpoints are owned by Amazon Signed-off-by: Salim Afiune Maya <afiune@mondoo.com> --------- Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
1 parent 6fefe9e commit b73ea17

File tree

5 files changed

+312
-61
lines changed

5 files changed

+312
-61
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Mondoo, Inc.
2+
// SPDX-License-Identifier: BUSL-1.1
3+
4+
package convert
5+
6+
// Func defines a function type that converts an element of type T to V.
7+
type Func[T any, V any] func(T) V
8+
9+
// Into converts a slice of type `T` to a slice of type `V` by applying the
10+
// convert function `Func`.
11+
//
12+
// Example usage:
13+
//
14+
// 1. Convert a slice of integers to a slice of strings:
15+
//
16+
// ints := []int{1, 2, 3}
17+
// strs := Into(ints, func(i int) string {
18+
// return fmt.Sprintf("%d", i)
19+
// })
20+
//
21+
// // Output: []string{"1", "2", "3"}
22+
//
23+
// 2. Convert a slice of structs into a slice of strings:
24+
//
25+
// type Person struct {
26+
// Name string
27+
// Age int
28+
// }
29+
//
30+
// people := []Person{
31+
// {Name: "Alice", Age: 30},
32+
// {Name: "Bob", Age: 25},
33+
// }
34+
//
35+
// names := Into(people, func(p Person) string {
36+
// return p.Name
37+
// })
38+
//
39+
// // Output: []string{"Alice", "Bob"}
40+
func Into[T any, V any](sliceT []T, convertFn Func[T, V]) []V {
41+
sliceV := make([]V, len(sliceT))
42+
for i, item := range sliceT {
43+
sliceV[i] = convertFn(item)
44+
}
45+
return sliceV
46+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright (c) Mondoo, Inc.
2+
// SPDX-License-Identifier: BUSL-1.1
3+
4+
package convert_test
5+
6+
import (
7+
"strconv"
8+
"testing"
9+
10+
"go.mondoo.com/cnquery/v11/providers-sdk/v1/util/convert"
11+
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestInto(t *testing.T) {
16+
t.Run("Convert int to string", func(t *testing.T) {
17+
input := []int{1, 2, 3, 4, 5}
18+
output := convert.Into(input, func(i int) string {
19+
return strconv.Itoa(i)
20+
})
21+
expected := []string{"1", "2", "3", "4", "5"}
22+
assert.Equal(t, expected, output)
23+
})
24+
25+
t.Run("Convert float64 to string", func(t *testing.T) {
26+
input := []float64{1.1, 2.2, 3.3}
27+
output := convert.Into(input, func(f float64) string {
28+
return strconv.FormatFloat(f, 'f', 1, 64)
29+
})
30+
expected := []string{"1.1", "2.2", "3.3"}
31+
assert.Equal(t, expected, output)
32+
})
33+
34+
t.Run("Convert struct to string", func(t *testing.T) {
35+
type Person struct {
36+
Name string
37+
}
38+
input := []Person{{"Alice"}, {"Bob"}, {"Charlie"}}
39+
output := convert.Into(input, func(p Person) string {
40+
return p.Name
41+
})
42+
expected := []string{"Alice", "Bob", "Charlie"}
43+
assert.Equal(t, expected, output)
44+
})
45+
46+
t.Run("Convert string to int", func(t *testing.T) {
47+
input := []string{"10", "20", "30"}
48+
output := convert.Into(input, func(s string) int {
49+
i, _ := strconv.Atoi(s)
50+
return i
51+
})
52+
expected := []int{10, 20, 30}
53+
assert.Equal(t, expected, output)
54+
})
55+
56+
t.Run("Convert bool to string", func(t *testing.T) {
57+
input := []bool{true, false, true}
58+
output := convert.Into(input, func(b bool) string {
59+
return strconv.FormatBool(b)
60+
})
61+
expected := []string{"true", "false", "true"}
62+
assert.Equal(t, expected, output)
63+
})
64+
65+
t.Run("Handle empty slice", func(t *testing.T) {
66+
input := []int{}
67+
output := convert.Into(input, func(i int) string {
68+
return strconv.Itoa(i)
69+
})
70+
expected := []string{}
71+
assert.Equal(t, expected, output)
72+
})
73+
74+
t.Run("Handle nil slice", func(t *testing.T) {
75+
var input []int
76+
output := convert.Into(input, func(i int) string {
77+
return strconv.Itoa(i)
78+
})
79+
assert.Empty(t, output)
80+
})
81+
82+
t.Run("Identity function", func(t *testing.T) {
83+
input := []string{"apple", "banana", "cherry"}
84+
output := convert.Into(input, func(s string) string {
85+
return s
86+
})
87+
expected := []string{"apple", "banana", "cherry"}
88+
assert.Equal(t, expected, output)
89+
})
90+
91+
t.Run("Convert complex numbers to string", func(t *testing.T) {
92+
input := []complex128{1 + 2i, 3 + 4i}
93+
output := convert.Into(input, func(c complex128) string {
94+
return strconv.FormatComplex(c, 'f', 1, 128)
95+
})
96+
expected := []string{"(1.0+2.0i)", "(3.0+4.0i)"}
97+
assert.Equal(t, expected, output)
98+
})
99+
100+
t.Run("Convert nested struct", func(t *testing.T) {
101+
type Outer struct {
102+
Inner struct {
103+
Value string
104+
}
105+
}
106+
input := []Outer{
107+
{Inner: struct{ Value string }{"one"}},
108+
{Inner: struct{ Value string }{"two"}},
109+
}
110+
output := convert.Into(input, func(o Outer) string {
111+
return o.Inner.Value
112+
})
113+
expected := []string{"one", "two"}
114+
assert.Equal(t, expected, output)
115+
})
116+
}

providers/aws/resources/aws.lr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,31 +2754,31 @@ private aws.vpc.natgateway.address {
27542754
// Amazon VPC Service Endpoint
27552755
private aws.vpc.serviceEndpoint {
27562756
// Whether acceptance is required
2757-
acceptanceRequired bool
2757+
acceptanceRequired() bool
27582758
// List of availability zones for the service endpoint
2759-
availabilityZones []string
2759+
availabilityZones() []string
27602760
// List of base endpoint DNS names for the service endpoint
27612761
dnsNames []string
27622762
// Service ID
27632763
id string
27642764
// Whether the service endpoint manages VPC endpoints
2765-
managesVpcEndpoints bool
2765+
managesVpcEndpoints() bool
27662766
// Service name
27672767
name string
27682768
// Service owner
27692769
owner string
27702770
// Service payer responsibility
2771-
payerResponsibility string
2771+
payerResponsibility() string
27722772
// Service private DNS name verification state
2773-
privateDnsNameVerificationState string
2773+
privateDnsNameVerificationState() string
27742774
// List of service private DNS names
2775-
privateDnsNames []string
2775+
privateDnsNames() []string
27762776
// Tags for the service endpoint
27772777
tags map[string]string
27782778
// Service type
27792779
type string
27802780
// Whether the service supports VPC endpoint policy
2781-
vpcEndpointPolicySupported bool
2781+
vpcEndpointPolicySupported() bool
27822782
}
27832783

27842784
// Amazon VPC Peering Connection

providers/aws/resources/aws.lr.go

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)