github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/logzio/logzio_provider.go (about) 1 // Copyright 2018 The Terraformer Authors. 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 logzio 16 17 import ( 18 "regexp" 19 "strings" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/pkg/errors" 23 "github.com/zclconf/go-cty/cty" 24 ) 25 26 type LogzioProvider struct { //nolint 27 terraformutils.Provider 28 apiToken string 29 baseURL string 30 } 31 32 var ( 33 disallowedChars = regexp.MustCompile(`[^A-Za-z0-9-]`) 34 ) 35 36 func (p LogzioProvider) GetResourceConnections() map[string]map[string][]string { 37 return map[string]map[string][]string{ 38 "alerts": {"alert_notification_endpoints": []string{"alert_notification_endpoints", "id"}}, 39 } 40 } 41 42 func (p LogzioProvider) GetProviderData(arg ...string) map[string]interface{} { 43 return map[string]interface{}{} 44 } 45 46 func (p *LogzioProvider) GetConfig() cty.Value { 47 return cty.ObjectVal(map[string]cty.Value{ 48 "api_token": cty.StringVal(p.apiToken), 49 "base_url": cty.StringVal(p.baseURL), 50 }) 51 } 52 53 // Init LogzioProvider with API apiToken 54 func (p *LogzioProvider) Init(args []string) error { 55 p.apiToken = args[0] 56 p.baseURL = args[1] 57 return nil 58 } 59 60 func (p *LogzioProvider) GetName() string { 61 return "logzio" 62 } 63 64 func (p *LogzioProvider) InitService(serviceName string, verbose bool) error { 65 var isSupported bool 66 if _, isSupported = p.GetSupportedService()[serviceName]; !isSupported { 67 return errors.New(p.GetName() + ": " + serviceName + " not supported service") 68 } 69 p.Service = p.GetSupportedService()[serviceName] 70 p.Service.SetName(serviceName) 71 p.Service.SetVerbose(verbose) 72 p.Service.SetProviderName(p.GetName()) 73 p.Service.SetArgs(map[string]interface{}{ 74 "api_token": p.apiToken, 75 "base_url": p.baseURL, 76 }) 77 return nil 78 } 79 80 // GetSupportedService return map of support service for Logzio 81 func (p *LogzioProvider) GetSupportedService() map[string]terraformutils.ServiceGenerator { 82 return map[string]terraformutils.ServiceGenerator{ 83 "alerts": &AlertsGenerator{}, 84 "alert_notification_endpoints": &AlertNotificationEndpointsGenerator{}, 85 } 86 } 87 88 func createSlug(s string) string { 89 s = strings.ToLower(s) 90 91 return disallowedChars.ReplaceAllString(s, "-") 92 }