github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/okta_service.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 okta 16 17 import ( 18 "context" 19 "fmt" 20 21 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 22 "github.com/okta/okta-sdk-golang/v2/okta" 23 "github.com/okta/terraform-provider-okta/sdk" 24 ) 25 26 type OktaService struct { //nolint 27 terraformutils.Service 28 } 29 30 func (s *OktaService) Client() (context.Context, *okta.Client, error) { 31 orgName := s.Args["org_name"].(string) 32 baseURL := s.Args["base_url"].(string) 33 apiToken := s.Args["api_token"].(string) 34 35 orgURL := fmt.Sprintf("https://%v.%v", orgName, baseURL) 36 37 ctx, client, err := okta.NewClient( 38 context.Background(), 39 okta.WithOrgUrl(orgURL), 40 okta.WithToken(apiToken), 41 ) 42 if err != nil { 43 return ctx, nil, err 44 } 45 46 return ctx, client, nil 47 } 48 49 func (s *OktaService) APISupplementClient() (context.Context, *sdk.APISupplement, error) { 50 baseURL := s.Args["base_url"].(string) 51 orgName := s.Args["org_name"].(string) 52 apiToken := s.Args["api_token"].(string) 53 54 orgURL := fmt.Sprintf("https://%v.%v", orgName, baseURL) 55 56 ctx, client, err := okta.NewClient( 57 context.Background(), 58 okta.WithOrgUrl(orgURL), 59 okta.WithToken(apiToken), 60 ) 61 if err != nil { 62 return ctx, nil, err 63 } 64 65 apiSupplementClient := &sdk.APISupplement{ 66 RequestExecutor: client.CloneRequestExecutor(), 67 } 68 69 return ctx, apiSupplementClient, nil 70 }