-
Notifications
You must be signed in to change notification settings - Fork 5
/
collectioncheckermanifest.go
49 lines (40 loc) · 1.1 KB
/
collectioncheckermanifest.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
package gocbcorex
import "context"
type CollectionCheckerManifest struct {
ManifestFetcher ManifestFetcher
}
var _ CollectionChecker = (*CollectionCheckerManifest)(nil)
func (c *CollectionCheckerManifest) HasScope(ctx context.Context, bucketName, scopeName string) (bool, error) {
manifest, err := c.ManifestFetcher.GetManifest(ctx, bucketName)
if err != nil {
return false, contextualError{
Cause: err,
Message: "failed to fetch manifest",
}
}
for _, scope := range manifest.Scopes {
if scope.Name == scopeName {
return true, nil
}
}
return false, nil
}
func (c *CollectionCheckerManifest) HasCollection(ctx context.Context, bucketName, scopeName, collectionName string) (bool, error) {
manifest, err := c.ManifestFetcher.GetManifest(ctx, bucketName)
if err != nil {
return false, contextualError{
Cause: err,
Message: "failed to fetch manifest",
}
}
for _, scope := range manifest.Scopes {
if scope.Name == scopeName {
for _, collection := range scope.Collections {
if collection.Name == collectionName {
return true, nil
}
}
}
}
return false, nil
}