...

Source file src/google.golang.org/grpc/xds/bootstrap/credentials.go

Documentation: google.golang.org/grpc/xds/bootstrap

     1  /*
     2   *
     3   * Copyright 2024 gRPC authors.
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   */
    18  
    19  package bootstrap
    20  
    21  import (
    22  	"encoding/json"
    23  
    24  	"google.golang.org/grpc/credentials"
    25  	"google.golang.org/grpc/credentials/google"
    26  	"google.golang.org/grpc/credentials/insecure"
    27  	"google.golang.org/grpc/internal/xds/bootstrap/tlscreds"
    28  )
    29  
    30  func init() {
    31  	RegisterCredentials(&insecureCredsBuilder{})
    32  	RegisterCredentials(&googleDefaultCredsBuilder{})
    33  	RegisterCredentials(&tlsCredsBuilder{})
    34  }
    35  
    36  // insecureCredsBuilder implements the `Credentials` interface defined in
    37  // package `xds/bootstrap` and encapsulates an insecure credential.
    38  type insecureCredsBuilder struct{}
    39  
    40  func (i *insecureCredsBuilder) Build(json.RawMessage) (credentials.Bundle, func(), error) {
    41  	return insecure.NewBundle(), func() {}, nil
    42  }
    43  
    44  func (i *insecureCredsBuilder) Name() string {
    45  	return "insecure"
    46  }
    47  
    48  // tlsCredsBuilder implements the `Credentials` interface defined in
    49  // package `xds/bootstrap` and encapsulates a TLS credential.
    50  type tlsCredsBuilder struct{}
    51  
    52  func (t *tlsCredsBuilder) Build(config json.RawMessage) (credentials.Bundle, func(), error) {
    53  	return tlscreds.NewBundle(config)
    54  }
    55  
    56  func (t *tlsCredsBuilder) Name() string {
    57  	return "tls"
    58  }
    59  
    60  // googleDefaultCredsBuilder implements the `Credentials` interface defined in
    61  // package `xds/boostrap` and encapsulates a Google Default credential.
    62  type googleDefaultCredsBuilder struct{}
    63  
    64  func (d *googleDefaultCredsBuilder) Build(json.RawMessage) (credentials.Bundle, func(), error) {
    65  	return google.NewDefaultCredentials(), func() {}, nil
    66  }
    67  
    68  func (d *googleDefaultCredsBuilder) Name() string {
    69  	return "google_default"
    70  }
    71  

View as plain text