github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/okta/authorization_server_claim.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  	"github.com/GoogleCloudPlatform/terraformer/terraformutils"
    19  	"github.com/okta/okta-sdk-golang/v2/okta"
    20  )
    21  
    22  type AuthorizationServerClaimGenerator struct {
    23  	OktaService
    24  }
    25  
    26  func (g AuthorizationServerClaimGenerator) createResources(authorizationServerClaimList []*okta.OAuth2Claim, authorizationServerID string, authorizationServerName string) []terraformutils.Resource {
    27  	var resources []terraformutils.Resource
    28  
    29  	for _, authorizationServerClaim := range authorizationServerClaimList {
    30  		resourceType := "okta_auth_server_claim"
    31  		if authorizationServerClaim.Name == "sub" {
    32  			resourceType = "okta_auth_server_claim_default"
    33  		}
    34  		resources = append(resources, terraformutils.NewResource(
    35  			authorizationServerClaim.Id,
    36  			normalizeResourceName("auth_server_"+authorizationServerName+"_claim_"+authorizationServerClaim.Id),
    37  			resourceType,
    38  			"okta",
    39  			map[string]string{
    40  				"auth_server_id": authorizationServerID,
    41  			},
    42  			[]string{},
    43  			map[string]interface{}{},
    44  		))
    45  	}
    46  	return resources
    47  }
    48  
    49  func (g *AuthorizationServerClaimGenerator) InitResources() error {
    50  	var resources []terraformutils.Resource
    51  	ctx, client, e := g.Client()
    52  	if e != nil {
    53  		return e
    54  	}
    55  
    56  	authorizationServers, err := getAuthorizationServers(ctx, client)
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	for _, authorizationServer := range authorizationServers {
    62  		output, _, err := client.AuthorizationServer.ListOAuth2Claims(ctx, authorizationServer.Id)
    63  		if err != nil {
    64  			return err
    65  		}
    66  
    67  		resources = append(resources, g.createResources(output, authorizationServer.Id, authorizationServer.Name)...)
    68  	}
    69  
    70  	g.Resources = resources
    71  	return nil
    72  }