-
Notifications
You must be signed in to change notification settings - Fork 204
/
patches.go
63 lines (57 loc) · 2.56 KB
/
patches.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
// Copyright 2022 Google LLC
//
// 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 dclschemaloader
import (
"github.com/nasa9084/go-openapi"
)
var correctedDCLResourceValueTemplateMap = map[string]string{
// TODO(b/179399619): remove following two entries once DCL fixes 'x-dcl-id' for MonitoringGroup and StorageBucket resources
"monitoring_ga_group": "projects/{{project}}/groups/{{name}}",
"storage_ga_bucket": "{{name}}",
}
var unsupportedDCLResourceValueTemplateMap = map[string]string{
// referenced by DLPStoredInfoType
"bigquery_beta_dataset": "projects/{{project}}/datasets/{{name}}",
"bigquery_beta_table": "projects/{{project}}/datasets/{{dataset_id}}/tables/{{name}}",
// referenced by DLPDeidentifyTemplate
"cloudkms_ga_cryptokey": "{{selfLink}}",
// referenced by RunService
"secretmanager_beta_secret": "projects/{{project}}/secrets/{{name}}",
// TODO(b/200559394): Support the relative resource name.
// {{name}} will be resolved to the short name, i.e. resourceID. It works
// for RunService because the API accepts the short name.
// There might be other cases where resources which reference
// secretmanager_beta_secretversion require the long name - the relative
// resource name, and it is not supported yet.
"secretmanager_beta_secretversion": "{{name}}",
"workflows_beta_workflow": "projects/{{project}}/locations/{{location}}/workflows/{{name}}",
}
// This function patches DCL schema for KCC's convenience.
func patchDCLSchemas(schemaMap map[string]*openapi.Schema) {
// Fix the OpenAPI schema for the resources with incorrect 'x-dcl-id's.
for resourceName, valueTemplate := range correctedDCLResourceValueTemplateMap {
s := schemaMap[resourceName]
s.Extension["x-dcl-id"] = valueTemplate
}
// Configure 'x-dcl-id' for the resources that are:
// (1) referenced by a DCL-based KCC resource, and
// (2) not yet supported in DCL.
for resourceName, valueTemplate := range unsupportedDCLResourceValueTemplateMap {
schemaMap[resourceName] = &openapi.Schema{
Extension: map[string]interface{}{
"x-dcl-id": valueTemplate,
},
}
}
}