github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/policy_signon.go (about) 1 // Copyright 2019 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 okta 16 17 import ( 18 "context" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "github.com/okta/okta-sdk-golang/v2/okta" 22 "github.com/okta/okta-sdk-golang/v2/okta/query" 23 ) 24 25 type SignOnPolicyGenerator struct { 26 OktaService 27 } 28 29 func (g SignOnPolicyGenerator) createResources(signOnPolicyList []*okta.Policy) []terraformutils.Resource { 30 var resources []terraformutils.Resource 31 for _, signOnPolicy := range signOnPolicyList { 32 resourceName := normalizeResourceName(signOnPolicy.Name) 33 resourceType := "okta_policy_signon" 34 35 resources = append(resources, terraformutils.NewSimpleResource( 36 signOnPolicy.Id, 37 "policy_signon_"+resourceName, 38 resourceType, 39 "okta", 40 []string{})) 41 } 42 return resources 43 } 44 45 func (g *SignOnPolicyGenerator) InitResources() error { 46 var output []*okta.Policy 47 ctx, client, e := g.Client() 48 if e != nil { 49 return e 50 } 51 52 output, _ = getSignOnPolicies(ctx, client) 53 g.Resources = g.createResources(output) 54 return nil 55 } 56 57 func getSignOnPolicies(ctx context.Context, client *okta.Client) ([]*okta.Policy, error) { 58 qp := query.NewQueryParams(query.WithType("OKTA_SIGN_ON")) 59 output, resp, err := client.Policy.ListPolicies(ctx, qp) 60 if err != nil { 61 return nil, err 62 } 63 64 for resp.HasNextPage() { 65 var nextPolicySet []*okta.Policy 66 resp, _ = resp.Next(ctx, &nextPolicySet) 67 output = append(output, nextPolicySet...) 68 } 69 70 return output, nil 71 }