vitess.io/vitess@v0.16.2/go/mysql/auth_server_none.go (about)

     1  /*
     2  Copyright 2019 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package mysql
    18  
    19  import (
    20  	"net"
    21  
    22  	querypb "vitess.io/vitess/go/vt/proto/query"
    23  )
    24  
    25  // AuthServerNone takes all comers.
    26  // It's meant to be used for testing and prototyping.
    27  // With this config, you can connect to a local vtgate using
    28  // the following command line: 'mysql -P port -h ::'.
    29  // It only uses MysqlNativePassword method.
    30  type AuthServerNone struct {
    31  	methods []AuthMethod
    32  }
    33  
    34  // AuthMethods returns the list of registered auth methods
    35  // implemented by this auth server.
    36  func (a *AuthServerNone) AuthMethods() []AuthMethod {
    37  	return a.methods
    38  }
    39  
    40  // DefaultAuthMethodDescription returns MysqlNativePassword as the default
    41  // authentication method for the auth server implementation.
    42  func (a *AuthServerNone) DefaultAuthMethodDescription() AuthMethodDescription {
    43  	return MysqlNativePassword
    44  }
    45  
    46  // HandleUser validates if this user can use this auth method
    47  func (a *AuthServerNone) HandleUser(user string) bool {
    48  	return true
    49  }
    50  
    51  // UserEntryWithHash validates the user if it exists and returns the information.
    52  // Always accepts any user.
    53  func (a *AuthServerNone) UserEntryWithHash(conn *Conn, salt []byte, user string, authResponse []byte, remoteAddr net.Addr) (Getter, error) {
    54  	return &NoneGetter{}, nil
    55  }
    56  
    57  func init() {
    58  	a := NewAuthServerNone()
    59  	RegisterAuthServer("none", a)
    60  }
    61  
    62  // NewAuthServerNone returns an empty auth server. Always accepts all clients.
    63  func NewAuthServerNone() *AuthServerNone {
    64  	a := &AuthServerNone{}
    65  	a.methods = []AuthMethod{NewMysqlNativeAuthMethod(a, a)}
    66  	return a
    67  }
    68  
    69  // NoneGetter holds the empty string
    70  type NoneGetter struct{}
    71  
    72  // Get returns the empty string
    73  func (ng *NoneGetter) Get() *querypb.VTGateCallerID {
    74  	return &querypb.VTGateCallerID{Username: "userData1"}
    75  }