Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit ad1c401

Browse files
authored
GCP Billing and Azure Event Grid sources added (#212)
1 parent 399f7bb commit ad1c401

File tree

8 files changed

+266
-64
lines changed

8 files changed

+266
-64
lines changed

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/spf13/viper v1.14.0
1818
github.com/stretchr/testify v1.8.1
1919
github.com/triggermesh/brokers v1.0.0
20-
github.com/triggermesh/triggermesh v1.22.0
20+
github.com/triggermesh/triggermesh v1.22.1-0.20230109081212-641ec5587aef
2121
github.com/triggermesh/triggermesh-core v1.0.0
2222
google.golang.org/api v0.105.0
2323
gopkg.in/yaml.v3 v3.0.1
@@ -40,7 +40,7 @@ require (
4040
contrib.go.opencensus.io/exporter/ocagent v0.7.1-0.20200907061046-05415f1de66d // indirect
4141
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
4242
contrib.go.opencensus.io/exporter/zipkin v0.1.2 // indirect
43-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.4 // indirect
43+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.2.0 // indirect
4444
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
4545
github.com/Azure/go-autorest/autorest/adal v0.9.21 // indirect
4646
github.com/Azure/go-autorest/autorest/azure/cli v0.4.5 // indirect
@@ -127,7 +127,7 @@ require (
127127
github.com/spf13/pflag v1.0.5 // indirect
128128
github.com/stoewer/go-strcase v1.2.0 // indirect
129129
github.com/subosito/gotenv v1.4.1 // indirect
130-
github.com/tidwall/gjson v1.14.3 // indirect
130+
github.com/tidwall/gjson v1.14.4 // indirect
131131
github.com/tidwall/match v1.1.1 // indirect
132132
github.com/tidwall/pretty v1.2.0 // indirect
133133
go.opencensus.io v0.24.0 // indirect
@@ -136,11 +136,11 @@ require (
136136
go.uber.org/multierr v1.8.0 // indirect
137137
go.uber.org/zap v1.23.0 // indirect
138138
golang.org/x/crypto v0.1.0 // indirect
139-
golang.org/x/net v0.2.0 // indirect
139+
golang.org/x/net v0.4.0 // indirect
140140
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect
141141
golang.org/x/sync v0.1.0 // indirect
142-
golang.org/x/sys v0.2.0 // indirect
143-
golang.org/x/term v0.2.0 // indirect
142+
golang.org/x/sys v0.3.0 // indirect
143+
golang.org/x/term v0.3.0 // indirect
144144
golang.org/x/text v0.5.0 // indirect
145145
golang.org/x/time v0.1.0 // indirect
146146
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect

go.sum

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ github.com/Antonboom/errname v0.1.5/go.mod h1:DugbBstvPFQbv/5uLcRRzfrNqKE9tVdVCq
8585
github.com/Antonboom/nilnil v0.1.0/go.mod h1:PhHLvRPSghY5Y7mX4TW+BHZQYo1A8flE5H20D3IPZBo=
8686
github.com/Azure/azure-sdk-for-go v67.1.0+incompatible h1:oziYcaopbnIKfM69DL05wXdypiqfrUKdxUKrKpynJTw=
8787
github.com/Azure/azure-sdk-for-go v67.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
88-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.4 h1:pqrAR74b6EoR4kcxF7L7Wg2B8Jgil9UUZtMvxhEFqWo=
89-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.4/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
88+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.2.0 h1:sVW/AFBTGyJxDaMYlq0ct3jUXTtj12tQ6zE2GZUgVQw=
89+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.2.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
9090
github.com/Azure/go-ansiterm v0.0.0-20210608223527-2377c96fe795/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
9191
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8=
9292
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
@@ -998,8 +998,8 @@ github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b/go.mod h1:yHp0
998998
github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0=
999999
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY=
10001000
github.com/tetafro/godot v1.4.11/go.mod h1:LR3CJpxDVGlYOWn3ZZg1PgNZdTUvzsZWu8xaEohUpn8=
1001-
github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw=
1002-
github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
1001+
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
1002+
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
10031003
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
10041004
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
10051005
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
@@ -1016,8 +1016,12 @@ github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoi
10161016
github.com/tommy-muehle/go-mnd/v2 v2.4.0/go.mod h1:WsUAkMJMYww6l/ufffCD3m+P7LEvr8TnZn9lwVDlgzw=
10171017
github.com/triggermesh/brokers v1.0.0 h1:XQiFFtYNMJeNhLUSSXgPkaFj4q9EnigCVR6g0XboJS4=
10181018
github.com/triggermesh/brokers v1.0.0/go.mod h1:8tqxffAcoVUGqb2sQLPrfu3PaZ6vK3q6+oqPJH2XUq4=
1019-
github.com/triggermesh/triggermesh v1.22.0 h1:u0Sie90czBxkMc/zgsXZqRwHOkGFMggL7K48tGO8ctE=
1020-
github.com/triggermesh/triggermesh v1.22.0/go.mod h1:KMjb69J/4aufYEXGHUwJi3DC7JdQPYE6BLbvDo9d++o=
1019+
github.com/triggermesh/triggermesh v1.22.1-0.20230109061818-a1d6e63f8e0f h1:6bKnmCdI37jNFk6diDwdVwsGf0mJN/O3TqEhHpGDlxU=
1020+
github.com/triggermesh/triggermesh v1.22.1-0.20230109061818-a1d6e63f8e0f/go.mod h1:CPokXPNGdoqG9tWbIZwBR5n3KFy03HOpx8pRrsOVnTQ=
1021+
github.com/triggermesh/triggermesh v1.22.1-0.20230109062658-2671588cde80 h1:05utMhslnhN41p8rSDnl83uil3x4cd6e7qsb0/oQPEY=
1022+
github.com/triggermesh/triggermesh v1.22.1-0.20230109062658-2671588cde80/go.mod h1:CPokXPNGdoqG9tWbIZwBR5n3KFy03HOpx8pRrsOVnTQ=
1023+
github.com/triggermesh/triggermesh v1.22.1-0.20230109081212-641ec5587aef h1:GNuSTJauULsqWsAft40o5uZXujkFyByiX+VLqmo3c+k=
1024+
github.com/triggermesh/triggermesh v1.22.1-0.20230109081212-641ec5587aef/go.mod h1:CPokXPNGdoqG9tWbIZwBR5n3KFy03HOpx8pRrsOVnTQ=
10211025
github.com/triggermesh/triggermesh-core v1.0.0 h1:87ZfIj6ms/ahdl4Eq4q6qKJG2aRPvSyclA5SURwHE0A=
10221026
github.com/triggermesh/triggermesh-core v1.0.0/go.mod h1:TV9g+gg6P11x3B7/UfhxfSHD9yWv2JJO20fHa675cMo=
10231027
github.com/tsenart/go-tsz v0.0.0-20180814232043-cdeb9e1e981e/go.mod h1:SWZznP1z5Ki7hDT2ioqiFKEse8K9tU2OUvaRI0NeGQo=
@@ -1245,8 +1249,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
12451249
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
12461250
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
12471251
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
1248-
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
1249-
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
1252+
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
1253+
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
12501254
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
12511255
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
12521256
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -1379,14 +1383,14 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
13791383
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13801384
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13811385
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1382-
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
1383-
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1386+
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
1387+
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
13841388
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
13851389
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
13861390
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
13871391
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
1388-
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
1389-
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
1392+
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
1393+
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
13901394
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
13911395
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
13921396
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

pkg/triggermesh/adapter/ce/sources.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ func sources(object unstructured.Unstructured) (EventAttributes, error) {
117117
ProducedEventTypes: o.GetEventTypes(),
118118
ProducedEventSource: o.AsEventSource(),
119119
}, nil
120-
// Multitenant
121-
// case "AWSSNSSource":
122-
// var o *sourcesv1alpha1.AWSSNSSource
123-
// if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
124-
// return nil, err
125-
// }
126-
// return awssnssource.MakeAppEnv(o), nil
127120
case "AWSSQSSource":
128121
var o *sourcesv1alpha1.AWSSQSSource
129122
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
@@ -331,13 +324,9 @@ func sources(object unstructured.Unstructured) (EventAttributes, error) {
331324
ProducedEventTypes: o.GetEventTypes(),
332325
ProducedEventSource: o.AsEventSource(),
333326
}, nil
334-
// Multitenant
335-
// case "ZendeskSource":
336-
// var o *sourcesv1alpha1.ZendeskSource
337-
// if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
338-
// return nil, err
339-
// }
340-
// return zendesksource.MakeAppEnv(o), nil
327+
// Multitenant
328+
case "AWSSNSSource", "ZendeskSource":
329+
return EventAttributes{}, fmt.Errorf("kind %q is multitenant and not suitable for local environment", object.GetKind())
341330
}
342331

343332
return EventAttributes{}, fmt.Errorf("kind %q is not supported", object.GetKind())

pkg/triggermesh/adapter/env/sources.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ func sources(object unstructured.Unstructured) ([]corev1.EnvVar, error) {
121121
return nil, err
122122
}
123123
return awss3source.MakeAppEnv(o), nil
124-
// Multitenant
125-
// case "AWSSNSSource":
126-
// var o *sourcesv1alpha1.AWSSNSSource
127-
// if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
128-
// return nil, err
129-
// }
130-
// return awssnssource.MakeAppEnv(o), nil
131124
case "AWSSQSSource":
132125
var o *sourcesv1alpha1.AWSSQSSource
133126
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
@@ -262,13 +255,9 @@ func sources(object unstructured.Unstructured) ([]corev1.EnvVar, error) {
262255
return nil, err
263256
}
264257
return webhooksource.MakeAppEnv(o), nil
265-
// Multitenant
266-
// case "ZendeskSource":
267-
// var o *sourcesv1alpha1.ZendeskSource
268-
// if err := runtime.DefaultUnstructuredConverter.FromUnstructured(object.Object, &o); err != nil {
269-
// return nil, err
270-
// }
271-
// return zendesksource.MakeAppEnv(o), nil
258+
// Multitenant
259+
case "AWSSNSSource", "ZendeskSource":
260+
return nil, fmt.Errorf("kind %q is multitenant and not suitable for local environment", object.GetKind())
272261
}
273262
return nil, fmt.Errorf("kind %q is not supported", object.GetKind())
274263
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2022 TriggerMesh Inc.
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 azure
18+
19+
import (
20+
"errors"
21+
"net/http"
22+
"time"
23+
24+
"github.com/Azure/azure-sdk-for-go/profiles/2020-09-01/monitor/mgmt/insights"
25+
"github.com/Azure/go-autorest/autorest"
26+
27+
"github.com/triggermesh/triggermesh/pkg/apis/sources/v1alpha1"
28+
)
29+
30+
const ActivityLogsCrudTimeout = time.Second * 15
31+
32+
func ActivityLogsDiagsName(src *v1alpha1.AzureActivityLogsSource) string {
33+
// hardcoded value from the upstream
34+
return "io.triggermesh.azureactivitylogssource." + src.Namespace + "." + src.Name
35+
}
36+
37+
func IsNotFoundErr(err error) bool {
38+
if dErr := (autorest.DetailedError{}); errors.As(err, &dErr) {
39+
return dErr.StatusCode == http.StatusNotFound
40+
}
41+
return false
42+
}
43+
44+
func ActivityLogsClient(src *v1alpha1.AzureActivityLogsSource, authorizer autorest.Authorizer) (insights.EventCategoriesClient, insights.DiagnosticSettingsClient, error) {
45+
eventCatCli := insights.NewEventCategoriesClient(src.Spec.SubscriptionID)
46+
eventCatCli.Authorizer = authorizer
47+
48+
diagSettingsCli := insights.NewDiagnosticSettingsClient(src.Spec.SubscriptionID)
49+
diagSettingsCli.Authorizer = authorizer
50+
return eventCatCli, diagSettingsCli, nil
51+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2022 TriggerMesh Inc.
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 azure
18+
19+
import (
20+
azureeventgrid "github.com/Azure/azure-sdk-for-go/profiles/latest/eventgrid/mgmt/eventgrid"
21+
"github.com/Azure/azure-sdk-for-go/profiles/latest/eventhub/mgmt/eventhub"
22+
"github.com/Azure/azure-sdk-for-go/profiles/latest/resources/mgmt/resources"
23+
"github.com/Azure/go-autorest/autorest"
24+
25+
"github.com/triggermesh/triggermesh/pkg/apis/sources/v1alpha1"
26+
"github.com/triggermesh/triggermesh/pkg/sources/client/azure/eventgrid"
27+
)
28+
29+
func EventGridClient(src *v1alpha1.AzureEventGridSource, authorizer autorest.Authorizer) (
30+
eventgrid.SystemTopicsClient, eventgrid.ProvidersClient, eventgrid.ResourceGroupsClient, eventgrid.EventSubscriptionsClient, eventgrid.EventHubsClient) {
31+
sysTopicsCli := &eventgrid.SystemTopicsClientImpl{
32+
SystemTopicsClient: azureeventgrid.NewSystemTopicsClient(src.Spec.Scope.SubscriptionID),
33+
}
34+
sysTopicsCli.Authorizer = authorizer
35+
36+
providersCli := resources.NewProvidersClient(src.Spec.Scope.SubscriptionID)
37+
providersCli.Authorizer = authorizer
38+
39+
resGroupsCli := resources.NewGroupsClient(src.Spec.Scope.SubscriptionID)
40+
resGroupsCli.Authorizer = authorizer
41+
42+
eventSubsCli := &eventgrid.EventSubscriptionsClientImpl{
43+
SystemTopicEventSubscriptionsClient: azureeventgrid.NewSystemTopicEventSubscriptionsClient(src.Spec.Scope.SubscriptionID),
44+
}
45+
eventSubsCli.Authorizer = authorizer
46+
47+
eventHubsCli := eventhub.NewEventHubsClient(src.Spec.Scope.SubscriptionID)
48+
eventHubsCli.Authorizer = authorizer
49+
return sysTopicsCli, providersCli, resGroupsCli, eventSubsCli, eventHubsCli
50+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2022 TriggerMesh Inc.
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 gcp
18+
19+
import (
20+
"context"
21+
"fmt"
22+
23+
billing "cloud.google.com/go/billing/budgets/apiv1"
24+
"cloud.google.com/go/pubsub"
25+
sourcesv1alpha1 "github.com/triggermesh/triggermesh/pkg/apis/sources/v1alpha1"
26+
)
27+
28+
func CloudBillingClient(src *sourcesv1alpha1.GoogleCloudBillingSource, secrets map[string]string) (*pubsub.Client, *billing.BudgetClient, error) {
29+
ctx := context.Background()
30+
psClient, credsClientOptions, err := pubSubClient(ctx, src.Spec.PubSub, secrets)
31+
if err != nil {
32+
return nil, nil, err
33+
}
34+
biClient, err := billing.NewBudgetClient(ctx, credsClientOptions)
35+
if err != nil {
36+
return nil, nil, fmt.Errorf("creating Google Cloud Billing Budget API client: %w", err)
37+
}
38+
return psClient, biClient, nil
39+
}

0 commit comments

Comments
 (0)