/
logging_utils.go
executable file
·108 lines (96 loc) · 3.34 KB
/
logging_utils.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2024 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package logging provides types and functiosn for handling logging GCP resources.
package alpha
import (
"bytes"
"context"
"fmt"
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
)
// do makes a request to delete a log bucket if the name of the bucket is not
// "_Default" or "_Required"
func (op *deleteLogBucketOperation) do(ctx context.Context, r *LogBucket, c *Client) error {
_, err := c.GetLogBucket(ctx, r)
if err != nil {
if dcl.IsNotFound(err) {
c.Config.Logger.Infof("LogBucket not found, returning. Original error: %v", err)
return nil
}
c.Config.Logger.Warningf("GetLogBucket checking for existence. error: %v", err)
return err
}
if r.Name != nil && (*r.Name == "_Default" || *r.Name == "_Required") {
return nil
}
u, err := r.deleteURL(c.Config.BasePath)
if err != nil {
return err
}
// Delete should never have a body
body := &bytes.Buffer{}
_, err = dcl.SendRequest(ctx, c.Config, "DELETE", u, body, c.Config.RetryProvider)
if err != nil {
return fmt.Errorf("failed to delete LogBucket: %w", err)
}
return nil
}
func equalsLogMetricMetricDescriptorLabelsValueType(m, n *LogMetricMetricDescriptorLabelsValueTypeEnum) bool {
if m == nil && n == nil {
return true
}
v := *LogMetricMetricDescriptorLabelsValueTypeEnumRef("STRING")
w := *LogMetricMetricDescriptorLabelsValueTypeEnumRef("")
if m == nil || *m == w {
// m is nil or blank, should compare equal to blank or "STRING"
return n == nil || *n == v || *n == w
}
if n == nil || *n == w {
// n is nil or blank, should compare equal to blank or "STRING"
return *m == v || *m == w
}
return *m == *n
}
func canonicalizeLogMetricMetricDescriptorLabelsValueType(m, n interface{}) bool {
if m == nil && n == nil {
return true
}
mVal, _ := m.(*LogMetricMetricDescriptorLabelsValueTypeEnum)
nVal, _ := n.(*LogMetricMetricDescriptorLabelsValueTypeEnum)
return equalsLogMetricMetricDescriptorLabelsValueType(mVal, nVal)
}
func equalsLogMetricMetricDescriptorValueType(m, n *LogMetricMetricDescriptorValueTypeEnum) bool {
if m == nil && n == nil {
return true
}
v := *LogMetricMetricDescriptorValueTypeEnumRef("STRING")
w := *LogMetricMetricDescriptorValueTypeEnumRef("")
if m == nil || *m == w {
// m is nil or blank, should compare equal to blank or "STRING"
return n == nil || *n == v || *n == w
}
if n == nil || *n == w {
// n is nil or blank, should compare equal to blank or "STRING"
return *m == v || *m == w
}
return *m == *n
}
func canonicalizeLogMetricMetricDescriptorValueType(m, n interface{}) bool {
if m == nil && n == nil {
return true
}
mVal, _ := m.(*LogMetricMetricDescriptorValueTypeEnum)
nVal, _ := n.(*LogMetricMetricDescriptorValueTypeEnum)
return equalsLogMetricMetricDescriptorValueType(mVal, nVal)
}