github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/iamuum/iamuumv1/api_service.go (about)

     1  package iamuumv1
     2  
     3  import (
     4  	gohttp "net/http"
     5  
     6  	bluemix "github.com/IBM-Cloud/bluemix-go"
     7  	"github.com/IBM-Cloud/bluemix-go/authentication"
     8  	"github.com/IBM-Cloud/bluemix-go/client"
     9  	"github.com/IBM-Cloud/bluemix-go/http"
    10  	"github.com/IBM-Cloud/bluemix-go/rest"
    11  	"github.com/IBM-Cloud/bluemix-go/session"
    12  )
    13  
    14  //IAMUUMServiceAPI is the resource client ...
    15  type IAMUUMServiceAPI interface {
    16  	AccessGroup() AccessGroupRepository
    17  	AccessGroupMember() AccessGroupMemberRepository
    18  }
    19  
    20  //ErrCodeAPICreation ...
    21  const ErrCodeAPICreation = "APICreationError"
    22  
    23  //iamService holds the client
    24  type iamuumService struct {
    25  	*client.Client
    26  }
    27  
    28  //New ...
    29  func New(sess *session.Session) (IAMUUMServiceAPI, error) {
    30  	config := sess.Config.Copy()
    31  	err := config.ValidateConfigForService(bluemix.IAMUUMService)
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  	if config.HTTPClient == nil {
    36  		config.HTTPClient = http.NewHTTPClient(config)
    37  	}
    38  	tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{
    39  		DefaultHeader: gohttp.Header{
    40  			"X-Original-User-Agent": []string{config.UserAgent},
    41  			"User-Agent":            []string{http.UserAgent()},
    42  		},
    43  		HTTPClient: config.HTTPClient,
    44  	})
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  	if config.IAMAccessToken == "" {
    49  		err := authentication.PopulateTokens(tokenRefreher, config)
    50  		if err != nil {
    51  			return nil, err
    52  		}
    53  	}
    54  	if config.Endpoint == nil {
    55  		ep, err := config.EndpointLocator.IAMEndpoint()
    56  		if err != nil {
    57  			return nil, err
    58  		}
    59  		config.Endpoint = &ep
    60  	}
    61  
    62  	return &iamuumService{
    63  		Client: client.New(config, bluemix.IAMUUMService, tokenRefreher),
    64  	}, nil
    65  }
    66  
    67  //AccessGroup API
    68  func (a *iamuumService) AccessGroup() AccessGroupRepository {
    69  	return NewAccessGroupRepository(a.Client)
    70  }
    71  
    72  //AccessGroupMember API
    73  func (a *iamuumService) AccessGroupMember() AccessGroupMemberRepository {
    74  	return NewAccessGroupMemberRepository(a.Client)
    75  }