...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp/names.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package gcp
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  )
    21  
    22  func FormatBigtableInstanceName(projectId string, name string) string {
    23  	return fmt.Sprintf("projects/%v/instances/%v", projectId, name)
    24  }
    25  
    26  func FormatBigtableClusterName(projectId, instanceName, clusterName string) string {
    27  	return fmt.Sprintf("projects/%v/instances/%v/clusters/%v", projectId, instanceName, clusterName)
    28  }
    29  
    30  func FormatFullProjectID(projectId string) string {
    31  	return fmt.Sprintf("projects/%v", projectId)
    32  }
    33  
    34  func FormatComputeNetworkName(projectId, name string) string {
    35  	return fmt.Sprintf("projects/%v/global/networks/%v", projectId, name)
    36  }
    37  
    38  func FormatComputeRouterName(projectId, region, name string) string {
    39  	return fmt.Sprintf("projects/%v/regions/%v/routers/%v", projectId, region, name)
    40  }
    41  
    42  func FormatComputeSubNetworkName(projectId, region, name string) string {
    43  	return fmt.Sprintf("projects/%v/regions/%v/subnetworks/%v", projectId, region, name)
    44  }
    45  
    46  func FormatGlobalComputeSslCertificateName(projectId, name string) string {
    47  	return fmt.Sprintf("projects/%v/global/sslCertificates/%v", projectId, name)
    48  }
    49  
    50  func FormatPubSubTopicName(projectId, name string) string {
    51  	return fmt.Sprintf("projects/%v/topics/%v", projectId, name)
    52  }
    53  
    54  func FormatInstanceLocationName(projectId, name string) string {
    55  	return fmt.Sprintf("projects/%v/locations/%v", projectId, name)
    56  }
    57  
    58  func FullResourceNameToShortName(fullName string) string {
    59  	idx := strings.LastIndexAny(fullName, "/")
    60  	if idx == -1 {
    61  		return fullName
    62  	}
    63  	return fullName[idx+1:]
    64  }
    65  

View as plain text