github.com/greenpau/go-authcrunch@v1.1.4/pkg/messaging/file.go (about) 1 // Copyright 2022 Paul Greenberg greenpau@outlook.com 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 messaging 16 17 import ( 18 "github.com/greenpau/go-authcrunch/pkg/errors" 19 ) 20 21 // FileProvider represents file messaging provider which writes messages 22 // to a local file system, 23 type FileProvider struct { 24 Name string `json:"name,omitempty" xml:"name,omitempty" yaml:"name,omitempty"` 25 RootDir string `json:"root_dir,omitempty" xml:"root_dir,omitempty" yaml:"root_dir,omitempty"` 26 Templates map[string]string `json:"templates,omitempty" xml:"templates,omitempty" yaml:"templates,omitempty"` 27 } 28 29 // Validate validates FileProvider configuration. 30 func (e *FileProvider) Validate() error { 31 if e.Name == "" { 32 return errors.ErrMessagingProviderKeyValueEmpty.WithArgs("name") 33 } 34 35 if e.RootDir == "" { 36 return errors.ErrMessagingProviderKeyValueEmpty.WithArgs("root_dir") 37 } 38 39 if e.Templates != nil { 40 for k := range e.Templates { 41 switch k { 42 case "password_recovery": 43 case "registration_confirmation": 44 case "registration_ready": 45 case "registration_verdict": 46 case "mfa_otp": 47 default: 48 return errors.ErrMessagingProviderInvalidTemplate.WithArgs(k) 49 } 50 } 51 } 52 return nil 53 }