dubbo.apache.org/dubbo-go/v3@v3.1.1/xds/credentials/token_provider.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. 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 package credentials 19 20 import ( 21 "context" 22 "os" 23 ) 24 25 // provide k8s service account 26 type saTokenProvider struct { 27 Token string 28 tokenPath string 29 } 30 31 // NewSaTokenProvider return a provider 32 func NewSaTokenProvider(tokenPath string) (*saTokenProvider, error) { 33 sa, err := os.ReadFile(tokenPath) 34 if err != nil { 35 return nil, err 36 } 37 return &saTokenProvider{ 38 tokenPath: tokenPath, 39 Token: string(sa), 40 }, nil 41 } 42 43 // GetRequestMetadata return meta of authorization 44 func (s *saTokenProvider) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { 45 46 meta := make(map[string]string) 47 48 meta["authorization"] = "Bearer " + s.Token 49 return meta, nil 50 } 51 52 // RequireTransportSecurity always false 53 func (s *saTokenProvider) RequireTransportSecurity() bool { 54 return false 55 }