-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl: read service config #83
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 unmarshalling 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 | ||
} |
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/googleapis/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) | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file seems unrelated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
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{}, | ||
}, | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seem unrelated, but meh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was more for readability, but happy to put in a separate PR