-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
205 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 | ||
// | ||
// https://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 genclient | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"google.golang.org/genproto/googleapis/api/serviceconfig" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func ReadServiceConfig(serviceConfigPath string) (*serviceconfig.Service, error) { | ||
y, err := os.ReadFile(serviceConfigPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("error reading service config: %v", err) | ||
} | ||
|
||
var cfg serviceconfig.Service | ||
if err := yaml.Unmarshal(y, &cfg); err != nil { | ||
return nil, fmt.Errorf("error unmarshaling service config: %v", err) | ||
} | ||
|
||
// An API Service Config will always have a `name` so if it is not populated, | ||
// it's an invalid config. | ||
if cfg.GetName() == "" { | ||
return nil, fmt.Errorf("invalid API service config file %q", serviceConfigPath) | ||
} | ||
return &cfg, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 | ||
// | ||
// https://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 genclient | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/googleapis/google-cloud-rust/generator/internal/sample" | ||
"google.golang.org/genproto/googleapis/api/annotations" | ||
"google.golang.org/genproto/googleapis/api/serviceconfig" | ||
"google.golang.org/protobuf/types/known/apipb" | ||
) | ||
|
||
func TestReadServiceConfig(t *testing.T) { | ||
const serviceConfigPath = "../../testdata/google/cloud/secretmanager/v1/secretmanager_v1.yaml" | ||
got, err := ReadServiceConfig(serviceConfigPath) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if diff := cmp.Diff(sample.ServiceConfig, got, | ||
cmpopts.IgnoreUnexported(annotations.HttpRule{}), | ||
cmpopts.IgnoreUnexported(annotations.Http{}), | ||
cmpopts.IgnoreUnexported(apipb.Api{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.AuthenticationRule{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.Authentication{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.BackendRule{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.Backend{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.DocumentationRule{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.Documentation{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.OAuthRequirements{}), | ||
cmpopts.IgnoreUnexported(serviceconfig.Service{}), | ||
); diff != "" { | ||
t.Errorf("mismatch (-want +got):\n%s", diff) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// 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 | ||
// | ||
// https://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 sample provides sample data for testing. | ||
package sample | ||
|
||
import ( | ||
"google.golang.org/genproto/googleapis/api/annotations" | ||
"google.golang.org/genproto/googleapis/api/serviceconfig" | ||
"google.golang.org/protobuf/types/known/apipb" | ||
) | ||
|
||
var ServiceConfig = &serviceconfig.Service{ | ||
Name: "secretmanager.googleapis.com", | ||
Title: "Secret Manager API", | ||
Apis: []*apipb.Api{ | ||
{ | ||
Name: "google.cloud.secretmanager.v1.SecretManagerService", | ||
}, | ||
}, | ||
Documentation: &serviceconfig.Documentation{ | ||
Summary: "Stores sensitive data such as API keys, passwords, and certificates.\nProvides convenience while improving security.", | ||
Rules: []*serviceconfig.DocumentationRule{ | ||
{ | ||
Selector: "google.cloud.location.Locations.GetLocation", | ||
Description: "Gets information about a location.", | ||
}, | ||
{ | ||
Selector: "google.cloud.location.Locations.ListLocations", | ||
Description: "Lists information about the supported locations for this service.", | ||
}, | ||
}, | ||
Overview: "Secret Manager Overview", | ||
}, | ||
Backend: &serviceconfig.Backend{ | ||
Rules: []*serviceconfig.BackendRule{ | ||
{ | ||
Selector: "google.cloud.location.Locations.GetLocation", | ||
Deadline: 60, | ||
}, | ||
{ | ||
Selector: "google.cloud.location.Locations.ListLocations", | ||
Deadline: 60, | ||
}, | ||
{ | ||
Selector: "google.cloud.secretmanager.v1.SecretManagerService.*", | ||
Deadline: 60, | ||
}, | ||
}, | ||
}, | ||
Http: &annotations.Http{ | ||
Rules: []*annotations.HttpRule{ | ||
{ | ||
Selector: "google.cloud.location.Locations.GetLocation", | ||
}, | ||
{ | ||
Selector: "google.cloud.location.Locations.ListLocations", | ||
}, | ||
}, | ||
}, | ||
Authentication: &serviceconfig.Authentication{ | ||
Rules: []*serviceconfig.AuthenticationRule{ | ||
{ | ||
Selector: "google.cloud.location.Locations.GetLocation", | ||
Oauth: &serviceconfig.OAuthRequirements{}, | ||
}, | ||
{ | ||
Selector: "google.cloud.location.Locations.ListLocations", | ||
Oauth: &serviceconfig.OAuthRequirements{}, | ||
}, | ||
{ | ||
Selector: "google.cloud.secretmanager.v1.SecretManagerService.*", | ||
Oauth: &serviceconfig.OAuthRequirements{}, | ||
}, | ||
}, | ||
}, | ||
} |