-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tool: support config file in codegen
- Loading branch information
Showing
5 changed files
with
162 additions
and
37 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
dev/tools/controllerbuilder/config/bigquerydatatransfer.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 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. | ||
|
||
service: google.cloud.bigquery.datatransfer.v1 | ||
apiVersion: bigquerydatatransfer.cnrm.cloud.google.com/v1beta1 | ||
generateMapper: true | ||
resources: | ||
- kind: BigQueryDataTransferConfig | ||
protoName: TransferConfig | ||
skipScaffoldFiles: true # files were scaffolded using a previous template, making them incompatible with the new scaffolding template. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 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 codegen | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type ServiceConfig struct { | ||
Service string `yaml:"service"` | ||
APIVersion string `yaml:"apiVersion"` | ||
GenerateMapper bool `yaml:"generateMapper"` | ||
Resources []ResourceConfig `yaml:"resources"` | ||
} | ||
|
||
type ResourceConfig struct { | ||
Kind string `yaml:"kind"` | ||
ProtoName string `yaml:"protoName"` | ||
SkipScaffoldFiles bool `yaml:"skipScaffoldFiles"` | ||
} | ||
|
||
func LoadConfig(configPath string) (*ServiceConfig, error) { | ||
if configPath == "" { | ||
return nil, nil | ||
} | ||
|
||
data, err := os.ReadFile(configPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read config file: %v", err) | ||
} | ||
|
||
var config ServiceConfig | ||
if err := yaml.Unmarshal(data, &config); err != nil { | ||
return nil, fmt.Errorf("failed to parse config file: %v", err) | ||
} | ||
|
||
return &config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters