vitess.io/vitess@v0.16.2/go/vt/vtaclcheck/vtaclcheck.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 vtaclcheck analyzes a set of sql statements and returns the 18 // corresponding vtgate and vttablet query plans that will be executed 19 // on the given statements 20 package vtaclcheck 21 22 import ( 23 "fmt" 24 25 "vitess.io/vitess/go/mysql" 26 "vitess.io/vitess/go/vt/tableacl" 27 "vitess.io/vitess/go/vt/tableacl/simpleacl" 28 ) 29 30 // Options to control the explain process 31 type Options struct { 32 // AclFile is the file with the JSON acl configuration 33 ACLFile string 34 // StaticAuthFile is the file containing the mysql auth_server_static JSON 35 StaticAuthFile string 36 } 37 38 var options *Options 39 40 // Init sets up the fake execution environment 41 func Init(opts *Options) error { 42 // verify opts is defined 43 if opts == nil { 44 return fmt.Errorf("vtaclcheck.Init: opts is NULL") 45 } 46 // Verify options 47 if opts.ACLFile == "" && opts.StaticAuthFile == "" { 48 return fmt.Errorf("no options specified") 49 } 50 51 options = opts 52 53 return nil 54 } 55 56 // Run the check on the given file 57 func Run() error { 58 if options.ACLFile != "" { 59 tableacl.Register("simpleacl", &simpleacl.Factory{}) 60 err := tableacl.Init( 61 options.ACLFile, 62 func() {}, 63 ) 64 if err != nil { 65 return fmt.Errorf("fail to initialize Table ACL: %v", err) 66 } 67 68 fmt.Printf("JSON ACL file %s looks good\n", options.ACLFile) 69 } 70 71 if options.StaticAuthFile != "" { 72 mysql.RegisterAuthServerStaticFromParams(options.StaticAuthFile, "", 0) 73 74 fmt.Printf("Static auth file %s looks good\n", options.StaticAuthFile) 75 } 76 77 return nil 78 }