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

kubernetes-sigs / blob-csi-driver / 14315335951

07 Apr 2025 05:14PM UTC coverage: 78.258%. Remained the same
14315335951

Pull #1931

github

web-flow
chore(deps): bump golang.org/x/sync from 0.12.0 to 0.13.0

Bumps [golang.org/x/sync](https://github.com/golang/sync) from 0.12.0 to 0.13.0.
- [Commits](https://github.com/golang/sync/compare/v0.12.0...v0.13.0)

---
updated-dependencies:
- dependency-name: golang.org/x/sync
  dependency-version: 0.13.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #1931: chore(deps): bump golang.org/x/sync from 0.12.0 to 0.13.0

2336 of 2985 relevant lines covered (78.26%)

7.6 hits per line

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

89.8
/pkg/csi-common/utils.go
1
/*
2
Copyright 2017 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package csicommon
18

19
import (
20
        "encoding/json"
21
        "fmt"
22
        "net"
23
        "os"
24
        "runtime"
25
        "strings"
26

27
        "github.com/container-storage-interface/spec/lib/go/csi"
28
        "github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
29
        "golang.org/x/net/context"
30
        "google.golang.org/grpc"
31
        "k8s.io/klog/v2"
32
)
33

34
func ParseEndpoint(ep string) (string, string, error) {
15✔
35
        if strings.HasPrefix(strings.ToLower(ep), "unix://") || strings.HasPrefix(strings.ToLower(ep), "tcp://") {
25✔
36
                s := strings.SplitN(ep, "://", 2)
10✔
37
                if s[1] != "" {
19✔
38
                        return s[0], s[1], nil
9✔
39
                }
9✔
40
        }
41
        return "", "", fmt.Errorf("Invalid endpoint: %v", ep)
6✔
42
}
43

44
func Listen(ctx context.Context, endpoint string) (net.Listener, error) {
4✔
45
        proto, addr, err := ParseEndpoint(endpoint)
4✔
46
        if err != nil {
5✔
47
                klog.Errorf("%v", err)
1✔
48
                return nil, err
1✔
49
        }
1✔
50

51
        if proto == "unix" {
5✔
52
                if runtime.GOOS != "windows" {
4✔
53
                        addr = "/" + addr
2✔
54
                }
2✔
55
                if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
2✔
56
                        klog.Errorf("Failed to remove %s, error: %v", addr, err)
×
57
                        return nil, err
×
58
                }
×
59
        }
60
        listenConfig := net.ListenConfig{}
3✔
61
        listener, err := listenConfig.Listen(ctx, proto, addr)
3✔
62
        if err != nil {
4✔
63
                klog.Errorf("Failed to listen: %v", err)
1✔
64
                return nil, err
1✔
65
        }
1✔
66
        return listener, nil
2✔
67
}
68

69
func NewVolumeCapabilityAccessMode(mode csi.VolumeCapability_AccessMode_Mode) *csi.VolumeCapability_AccessMode {
1✔
70
        return &csi.VolumeCapability_AccessMode{Mode: mode}
1✔
71
}
1✔
72

73
func NewControllerServiceCapability(c csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
12✔
74
        return &csi.ControllerServiceCapability{
12✔
75
                Type: &csi.ControllerServiceCapability_Rpc{
12✔
76
                        Rpc: &csi.ControllerServiceCapability_RPC{
12✔
77
                                Type: c,
12✔
78
                        },
12✔
79
                },
12✔
80
        }
12✔
81
}
12✔
82

83
func NewNodeServiceCapability(c csi.NodeServiceCapability_RPC_Type) *csi.NodeServiceCapability {
8✔
84
        return &csi.NodeServiceCapability{
8✔
85
                Type: &csi.NodeServiceCapability_Rpc{
8✔
86
                        Rpc: &csi.NodeServiceCapability_RPC{
8✔
87
                                Type: c,
8✔
88
                        },
8✔
89
                },
8✔
90
        }
8✔
91
}
8✔
92

93
func getLogLevel(method string) int32 {
10✔
94
        if method == "/csi.v1.Identity/Probe" ||
10✔
95
                method == "/csi.v1.Node/NodeGetCapabilities" ||
10✔
96
                method == "/csi.v1.Node/NodeGetVolumeStats" {
13✔
97
                return 6
3✔
98
        }
3✔
99
        return 2
7✔
100
}
101

102
func LogGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
5✔
103
        level := klog.Level(getLogLevel(info.FullMethod))
5✔
104
        klog.V(level).Infof("GRPC call: %s", info.FullMethod)
5✔
105
        klog.V(level).Infof("GRPC request: %s", StripSensitiveValue(protosanitizer.StripSecrets(req), "csi.storage.k8s.io/serviceAccount.tokens"))
5✔
106

5✔
107
        resp, err := handler(ctx, req)
5✔
108
        if err != nil {
5✔
109
                klog.Errorf("GRPC error: %v", err)
×
110
        } else {
5✔
111
                klog.V(level).Infof("GRPC response: %s", protosanitizer.StripSecrets(resp))
5✔
112
        }
5✔
113
        return resp, err
5✔
114
}
115

116
type stripSensitiveValue struct {
117
        // volume_context[key] is the value to be stripped.
118
        key string
119
        // req is the csi grpc request stripped by `protosanitizer.StripSecrets`
120
        req fmt.Stringer
121
}
122

123
func StripSensitiveValue(req fmt.Stringer, key string) fmt.Stringer {
5✔
124
        return &stripSensitiveValue{
5✔
125
                key: key,
5✔
126
                req: req,
5✔
127
        }
5✔
128
}
5✔
129

130
func (s *stripSensitiveValue) String() string {
5✔
131
        return stripSensitiveValueByKey(s.req, s.key)
5✔
132
}
5✔
133

134
func stripSensitiveValueByKey(req fmt.Stringer, key string) string {
5✔
135
        var parsed map[string]interface{}
5✔
136

5✔
137
        err := json.Unmarshal([]byte(req.String()), &parsed)
5✔
138
        if err != nil || parsed == nil {
5✔
139
                return req.String()
×
140
        }
×
141

142
        volumeContext, ok := parsed["volume_context"].(map[string]interface{})
5✔
143
        if !ok {
7✔
144
                return req.String()
2✔
145
        }
2✔
146

147
        if _, ok := volumeContext[key]; !ok {
3✔
148
                return req.String()
×
149
        }
×
150

151
        volumeContext[key] = "***stripped***"
3✔
152

3✔
153
        b, err := json.Marshal(parsed)
3✔
154
        if err != nil {
3✔
155
                return req.String()
×
156
        }
×
157

158
        return string(b)
3✔
159
}
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