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

Twingate / terraform-provider-twingate / 12287568180

12 Dec 2024 12:41AM UTC coverage: 57.177% (-4.9%) from 62.107%
12287568180

Pull #619

github

web-flow
Bump golang.org/x/crypto from 0.29.0 to 0.31.0

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.29.0 to 0.31.0.
- [Commits](https://github.com/golang/crypto/compare/v0.29.0...v0.31.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #619: Bump golang.org/x/crypto from 0.29.0 to 0.31.0

5079 of 8883 relevant lines covered (57.18%)

0.96 hits per line

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

24.32
/twingate/internal/provider/resource/helper.go
1
package resource
2

3
import (
4
        "context"
5
        "fmt"
6

7
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/model"
8
        "github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/utils"
9
        tfattr "github.com/hashicorp/terraform-plugin-framework/attr"
10
        "github.com/hashicorp/terraform-plugin-framework/diag"
11
        "github.com/hashicorp/terraform-plugin-framework/types"
12
)
13

14
// setIntersection - for given two sets A and B,
15
// A ∩ B (read as A intersection B) is the set of common elements that belong to set A and B.
16
// If A = {1, 2, 3, 4} and B = {3, 4, 5, 7}, then the intersection of A and B is given by A ∩ B = {3, 4}.
17
func setIntersection(a, b []string) []string {
1✔
18
        setA := utils.MakeLookupMap(a)
1✔
19
        setB := utils.MakeLookupMap(b)
1✔
20
        result := make([]string, 0, len(setA))
1✔
21

1✔
22
        for key := range setA {
2✔
23
                if setB[key] {
2✔
24
                        result = append(result, key)
1✔
25
                }
1✔
26
        }
27

28
        return result
1✔
29
}
30

31
func setIntersectionGroupAccess(inputA, inputB []model.AccessGroup) []model.AccessGroup {
×
32
        setA := map[string]model.AccessGroup{}
×
33
        setB := map[string]model.AccessGroup{}
×
34

×
35
        for _, access := range inputA {
×
36
                setA[access.GroupID] = access
×
37
        }
×
38

39
        for _, access := range inputB {
×
40
                setB[access.GroupID] = access
×
41
        }
×
42

43
        result := make([]model.AccessGroup, 0, len(setA))
×
44

×
45
        for key := range setA {
×
46
                if val, exist := setB[key]; exist {
×
47
                        result = append(result, val)
×
48
                }
×
49
        }
50

51
        return result
×
52
}
53

54
// setDifference - difference between sets implies subtracting the elements from a set.
55
// The difference between sets A and set B denoted as A − B.
56
// If A = {1, 2, 3, 4} and B = {3, 4, 5, 7}, then the difference between sets A and B is given by A - B = {1, 2}.
57
func setDifference(inputA, inputB []string) []string {
1✔
58
        if len(inputA) == 0 {
1✔
59
                return nil
×
60
        }
×
61

62
        if len(inputB) == 0 {
1✔
63
                return inputA
×
64
        }
×
65

66
        setA := utils.MakeLookupMap(inputA)
1✔
67
        setB := utils.MakeLookupMap(inputB)
1✔
68
        result := make([]string, 0, len(setA))
1✔
69

1✔
70
        for key := range setA {
2✔
71
                if !setB[key] {
2✔
72
                        result = append(result, key)
1✔
73
                }
1✔
74
        }
75

76
        return result
1✔
77
}
78

79
func setDifferenceGroupAccess(inputA, inputB []model.AccessGroup) []model.AccessGroup {
×
80
        setA := map[string]model.AccessGroup{}
×
81
        setB := map[string]model.AccessGroup{}
×
82

×
83
        for _, access := range inputA {
×
84
                setA[access.GroupID] = access
×
85
        }
×
86

87
        for _, access := range inputB {
×
88
                setB[access.GroupID] = access
×
89
        }
×
90

91
        result := make([]model.AccessGroup, 0, len(setA))
×
92

×
93
        for key, valA := range setA {
×
94
                if valB, exist := setB[key]; !exist || !valA.Equals(valB) {
×
95
                        result = append(result, valA)
×
96
                }
×
97
        }
98

99
        return result
×
100
}
101

102
func setDifferenceGroups(inputA, inputB []model.AccessGroup) []string {
×
103
        groupsA := utils.Map(inputA, func(item model.AccessGroup) string {
×
104
                return item.GroupID
×
105
        })
×
106

107
        groupsB := utils.Map(inputB, func(item model.AccessGroup) string {
×
108
                return item.GroupID
×
109
        })
×
110

111
        return setDifference(groupsA, groupsB)
×
112
}
113

114
func withDefaultValue(str, defaultValue string) string {
1✔
115
        if str != "" {
2✔
116
                return str
1✔
117
        }
1✔
118

119
        return defaultValue
1✔
120
}
121

122
func addErr(diagnostics *diag.Diagnostics, err error, operation, resource string) {
×
123
        if err == nil {
×
124
                return
×
125
        }
×
126

127
        diagnostics.AddError(
×
128
                fmt.Sprintf("failed to %s %s", operation, resource),
×
129
                err.Error(),
×
130
        )
×
131
}
132

133
func makeNullObject(attributeTypes map[string]tfattr.Type) types.Object {
×
134
        return types.ObjectNull(attributeTypes)
×
135
}
×
136

137
func makeObjectsSetNull(ctx context.Context, attributeTypes map[string]tfattr.Type) types.Set {
×
138
        return types.SetNull(types.ObjectNull(attributeTypes).Type(ctx))
×
139
}
×
140

141
func makeObjectsSet(ctx context.Context, objects ...types.Object) (types.Set, diag.Diagnostics) {
×
142
        obj := objects[0]
×
143

×
144
        items := utils.Map(objects, func(item types.Object) tfattr.Value {
×
145
                return tfattr.Value(item)
×
146
        })
×
147

148
        return types.SetValue(obj.Type(ctx), items)
×
149
}
150

151
// setUnion - for given two sets A and B,
152
// If A = {1, 2} and B = {3, 4}, then the union of A and B is {1, 2, 3, 4}.
153
func setUnion(setA, setB []string) []string {
×
154
        if len(setA) == 0 {
×
155
                return setB
×
156
        }
×
157

158
        if len(setB) == 0 {
×
159
                return setA
×
160
        }
×
161

162
        set := utils.MakeLookupMap(setA)
×
163

×
164
        for _, key := range setB {
×
165
                set[key] = true
×
166
        }
×
167

168
        result := make([]string, 0, len(set))
×
169
        for key := range set {
×
170
                result = append(result, key)
×
171
        }
×
172

173
        return result
×
174
}
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

© 2025 Coveralls, Inc