forked from instana/go-sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacl.go
84 lines (70 loc) · 2.64 KB
/
acl.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
77
78
79
80
81
82
83
84
// (c) Copyright IBM Corp. 2021
// (c) Copyright Instana Inc. 2020
//go:build go1.11
// +build go1.11
package storage
import (
"cloud.google.com/go/storage"
"context"
"github.com/mier85/go-sensor/instrumentation/cloud.google.com/go/internal"
"github.com/mier85/go-sensor/instrumentation/cloud.google.com/go/internal/tags"
ot "github.com/opentracing/opentracing-go"
)
// ACLHandle is an instrumented wrapper for cloud.google.com/go/storage.ACLHandle
// that traces calls made to Google Cloud Storage API.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#ACLHandle for further details on wrapped type.
type ACLHandle struct {
*storage.ACLHandle
Bucket string
Object string
Default bool
}
// Delete calls and traces the Delete() method of the wrapped cloud.google.com/go/storage.ACLHandle.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#ACLHandle.Delete for further details on wrapped method.
func (a *ACLHandle) Delete(ctx context.Context, entity storage.ACLEntity) (err error) {
ctx = internal.StartExitSpan(ctx, "gcs", ot.Tags{
tags.GcsOp: aclOpPrefix(a) + ".delete",
tags.GcsBucket: a.Bucket,
tags.GcsObject: a.Object,
tags.GcsEntity: string(entity),
})
defer func() { internal.FinishSpan(ctx, err) }()
return a.ACLHandle.Delete(ctx, entity)
}
// Set calls and traces the Set() method of the wrapped cloud.google.com/go/storage.ACLHandle.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#ACLHandle.Set for further details on wrapped method.
func (a *ACLHandle) Set(ctx context.Context, entity storage.ACLEntity, role storage.ACLRole) (err error) {
ctx = internal.StartExitSpan(ctx, "gcs", ot.Tags{
tags.GcsOp: aclOpPrefix(a) + ".update",
tags.GcsBucket: a.Bucket,
tags.GcsObject: a.Object,
tags.GcsEntity: string(entity),
})
defer func() { internal.FinishSpan(ctx, err) }()
return a.ACLHandle.Set(ctx, entity, role)
}
// List calls and traces the List() method of the wrapped cloud.google.com/go/storage.ACLHandle.
//
// See https://pkg.go.dev/cloud.google.com/go/storage?tab=doc#ACLHandle.List for further details on wrapped method.
func (a *ACLHandle) List(ctx context.Context) (rules []storage.ACLRule, err error) {
ctx = internal.StartExitSpan(ctx, "gcs", ot.Tags{
tags.GcsOp: aclOpPrefix(a) + ".list",
tags.GcsBucket: a.Bucket,
tags.GcsObject: a.Object,
})
defer func() { internal.FinishSpan(ctx, err) }()
return a.ACLHandle.List(ctx)
}
func aclOpPrefix(a *ACLHandle) string {
switch {
case a.Object != "": // object-specific ACL
return "objectAcls"
case a.Default: // default object ACL for a bucket
return "defaultAcls"
default: // bucket ACL
return "bucketAcls"
}
}