github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/idp_social.go (about) 1 // Copyright 2021 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 IdpSocialGenerator struct { 26 OktaService 27 } 28 29 func (g IdpSocialGenerator) createResources(idpSocialList []*okta.IdentityProvider) []terraformutils.Resource { 30 var resources []terraformutils.Resource 31 for _, idp := range idpSocialList { 32 resources = append(resources, terraformutils.NewSimpleResource( 33 idp.Id, 34 "idp_"+normalizeResourceName(idp.Type+"_"+idp.Name), 35 "okta_idp_social", 36 "okta", 37 []string{})) 38 39 } 40 return resources 41 } 42 43 // Generate Terraform Resources from Okta API, 44 func (g *IdpSocialGenerator) InitResources() error { 45 ctx, client, err := g.Client() 46 if err != nil { 47 return err 48 } 49 50 identityProviders, err := getIdpSocials(ctx, client) 51 if err != nil { 52 return err 53 } 54 55 g.Resources = g.createResources(identityProviders) 56 return nil 57 } 58 59 func getIdpSocials(ctx context.Context, client *okta.Client) ([]*okta.IdentityProvider, error) { 60 idpSocialTypes := []string{"APPLE", "FACEBOOK", "GOOGLE", "LINKEDIN", "MICROSOFT"} 61 var allIDPSocials []*okta.IdentityProvider 62 63 for _, idpSocialType := range idpSocialTypes { 64 qp := &query.Params{Type: idpSocialType, Limit: 1} 65 output, resp, err := client.IdentityProvider.ListIdentityProviders(ctx, qp) 66 if err != nil { 67 return nil, err 68 } 69 70 for resp.HasNextPage() { 71 var nextIdpSocialSet []*okta.IdentityProvider 72 resp, _ = resp.Next(ctx, &nextIdpSocialSet) 73 output = append(output, nextIdpSocialSet...) 74 } 75 76 allIDPSocials = append(allIDPSocials, output...) 77 } 78 79 return allIDPSocials, nil 80 }