Skip to content

Commit

Permalink
chore(internal/testing): update ServiceConfig with additional values (#…
Browse files Browse the repository at this point in the history
…1519)

* chore(internal/testing): update ServiceConfig with additional values

For #1512
  • Loading branch information
julieqiu authored May 15, 2024
1 parent a413e5d commit b455b1d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 17 deletions.
7 changes: 6 additions & 1 deletion internal/testing/sample/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "sample",
srcs = ["sample.go"],
srcs = [
"sample.go",
"serviceconfig.go",
],
importpath = "github.com/googleapis/gapic-generator-go/internal/testing/sample",
visibility = ["//:__subpackages__"],
deps = [
"@org_golang_google_genproto_googleapis_api//:api",
"@org_golang_google_genproto_googleapis_api//annotations",
"@org_golang_google_genproto_googleapis_api//serviceconfig",
"@org_golang_google_protobuf//proto",
"@org_golang_google_protobuf//types/descriptorpb",
Expand Down
23 changes: 7 additions & 16 deletions internal/testing/sample/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package sample
import (
"fmt"

"google.golang.org/genproto/googleapis/api/serviceconfig"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/descriptorpb"
"google.golang.org/protobuf/types/known/apipb"
)

const (
Expand Down Expand Up @@ -103,6 +101,13 @@ const (
// https://pkg.go.dev/cloud.google.com/go/secretmanager/apiv1/secretmanagerpb#Secret
// https://github.com/googleapis/googleapis/blob/f7df662a24c56ecaab79cb7d808fed4d2bb4981d/google/cloud/secretmanager/v1/resources.proto#L40
Resource = "Secret"

// CreateMethodWithSettings is a fake method for the purpose of testing
// the method_settings functionality in the publishing YAML.
//
// The actual secretmanager publishing does not use this field:
// https://github.com/googleapis/googleapis/blob/f7df662a24c56ecaab79cb7d808fed4d2bb4981d/google/cloud/secretmanager/v1/secretmanager_v1.yaml#L44
CreateMethodWithSettings = "CreateSecretWithMethodSettings"
)

const (
Expand Down Expand Up @@ -172,20 +177,6 @@ func DescriptorInfoTypeName(typ string) string {
return fmt.Sprintf(".%s.%s", ProtoPackagePath, typ)
}

// ServiceConfig returns service config information.
func ServiceConfig() *serviceconfig.Service {
return &serviceconfig.Service{
Apis: []*apipb.Api{
{
Name: fmt.Sprintf("%s.%s", ProtoPackagePath, ServiceName),
},
},
Documentation: &serviceconfig.Documentation{
Summary: ServiceDocumentationSummary,
},
}
}

// Service returns a service descriptor using the sample values.
func Service() *descriptorpb.ServiceDescriptorProto {
return &descriptorpb.ServiceDescriptorProto{
Expand Down
128 changes: 128 additions & 0 deletions internal/testing/sample/serviceconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// 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 functionality for generating sample values of
// the types contained in the internal package for testing purposes.
package sample

import (
"fmt"

"google.golang.org/genproto/googleapis/api"
"google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/genproto/googleapis/api/serviceconfig"
"google.golang.org/protobuf/types/known/apipb"
)

// ServiceConfig returns service config information.
func ServiceConfig() *serviceconfig.Service {
return &serviceconfig.Service{
Name: ServiceURL,
Title: ServiceTitle,
Apis: []*apipb.Api{
{
// This is a mix-in API, see https://google.aip.dev/client-libraries/4234 for more info.
Name: "google.cloud.location.Locations",
},
{
Name: fmt.Sprintf("%s.%s", ProtoPackagePath, ServiceName),
},
},
Documentation: &serviceconfig.Documentation{
Summary: "Stores sensitive data such as API keys, passwords, and certificates. Provides convenience while improving security.",
Overview: "Secret Manager Overview",
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.",
},
},
},
Http: &annotations.Http{
Rules: []*annotations.HttpRule{
{
Selector: "google.cloud.location.Locations.GetLocation",
Pattern: &annotations.HttpRule_Get{
Get: "/v1/{name=projects/*/locations/*}",
},
},
{
Selector: "google.cloud.location.Locations.ListLocation",
Pattern: &annotations.HttpRule_Get{
Get: "/v1/{name=projects/*}/locations",
},
},
},
},
Authentication: &serviceconfig.Authentication{
Rules: []*serviceconfig.AuthenticationRule{
{
Selector: "google.cloud.location.Locations.GetLocation",
Oauth: &serviceconfig.OAuthRequirements{
CanonicalScopes: ServiceOAuthScope,
},
},
{
Selector: "google.cloud.location.Locations.ListLocations",
Oauth: &serviceconfig.OAuthRequirements{
CanonicalScopes: ServiceOAuthScope,
},
},
{
Selector: "'google.cloud.secretmanager.v1.SecretManagerService.*'",
Oauth: &serviceconfig.OAuthRequirements{
CanonicalScopes: ServiceOAuthScope,
},
},
},
},
Publishing: &annotations.Publishing{
NewIssueUri: "https://issuetracker.google.com/issues/new?component=784854&template=1380926",
DocumentationUri: "https://cloud.google.com/secret-manager/docs/overview",
ApiShortName: "secretmanager",
GithubLabel: "'api: secretmanager'",
DocTagPrefix: "secretmanager",
Organization: annotations.ClientLibraryOrganization_CLOUD,
LibrarySettings: []*annotations.ClientLibrarySettings{
{
Version: "google.cloud.secretmanager.v1",
LaunchStage: api.LaunchStage_GA,
GoSettings: &annotations.GoSettings{
Common: &annotations.CommonLanguageSettings{
Destinations: []annotations.ClientLibraryDestination{
annotations.ClientLibraryDestination_PACKAGE_MANAGER,
},
},
},
},
},
ProtoReferenceDocumentationUri: "https://cloud.google.com/secret-manager/docs/reference/rpc",

// The data below is fake. method_settings is not used in
// https://github.com/googleapis/googleapis/blob/f7df662a24c56ecaab79cb7d808fed4d2bb4981d/google/cloud/secretmanager/v1/secretmanager_v1.yaml.
MethodSettings: []*annotations.MethodSettings{
{
Selector: fmt.Sprintf("%s.%s.%s", ProtoPackagePath, ServiceName, CreateMethodWithSettings),
AutoPopulatedFields: []string{
"request_id",
},
},
},
},
}
}

0 comments on commit b455b1d

Please sign in to comment.