github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/gmailfilter/filter.go (about) 1 // Copyright 2020 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 gmailfilter 16 17 import ( 18 "context" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "google.golang.org/api/gmail/v1" 22 ) 23 24 type FilterGenerator struct { 25 GmailfilterService 26 } 27 28 func (g FilterGenerator) createResources(filters []*gmail.Filter) []terraformutils.Resource { 29 var resources []terraformutils.Resource 30 for _, f := range filters { 31 resources = append(resources, terraformutils.NewResource( 32 f.Id, 33 f.Id, 34 "gmailfilter_filter", 35 "gmailfilter", 36 map[string]string{}, 37 []string{}, 38 map[string]interface{}{})) 39 } 40 return resources 41 } 42 43 func (g *FilterGenerator) InitResources() error { 44 ctx := context.Background() 45 gmailService, err := g.gmailService(ctx) 46 if err != nil { 47 return err 48 } 49 50 filters, err := gmailService.Users.Settings.Filters.List(gmailUser).Do() 51 if err != nil { 52 return err 53 } 54 g.Resources = append(g.Resources, g.createResources(filters.Filter)...) 55 56 return nil 57 }