Skip to content

Commit

Permalink
Support Get Account for v2/accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI authored and hkantare committed Apr 22, 2024
1 parent 5c5b994 commit 156c0e7
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/account/accountv1/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Accounts interface {
DeleteAccountUser(accountGuid string, userGuid string) error
FindAccountUserByUserId(accountGuid string, userId string) (*models.AccountUser, error)
List() ([]models.V2Account, error)
Get(accountId string) (models.V1Account, error)
}

type account struct {
Expand Down Expand Up @@ -257,3 +258,20 @@ func (a *account) List() ([]models.V2Account, error) {

return accounts, err
}

func (a *account) Get(accountId string) (models.V1Account, error) {
account := models.V1Account{}
response, err := a.client.Get(fmt.Sprintf("/coe/v2/accounts/%s", accountId), &account)
if err != nil {

if response.StatusCode == 404 {
return models.V1Account{}, bmxerror.New(ErrCodeNoAccountExists,
fmt.Sprintf("Account %q does not exists", accountId))
}
return models.V1Account{}, err

}

return account, nil

}
44 changes: 44 additions & 0 deletions examples/account/accountv1/get/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"flag"
"fmt"
"log"
"os"

bluemix "github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/api/account/accountv1"
"github.com/IBM-Cloud/bluemix-go/session"
"github.com/IBM-Cloud/bluemix-go/trace"
)

func main() {

var accountId string
flag.StringVar(&accountId, "accountId", "", "Bluemix Account ID")

if accountId == "" {
flag.Usage()
os.Exit(1)
}

c := new(bluemix.Config)
trace.Logger = trace.NewLogger("true")

sess, err := session.New(c)
if err != nil {
log.Fatal(err)
}

accClient1, err := accountv1.New(sess)
if err != nil {
log.Fatal(err)
}
accountAPIV1 := accClient1.Accounts()
//Get list of users under account
account, err := accountAPIV1.Get(accountId)
if err != nil {
log.Fatal(err)
}
fmt.Println("Accounts", account)
}
103 changes: 103 additions & 0 deletions models/accouts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package models

import "time"

type V2Account struct {
Guid string
Name string
Expand Down Expand Up @@ -31,3 +33,104 @@ type AccountUser struct {
InvitedOn string `json:"invitedOn"`
Photo string `json:"photo"`
}

type V1Account struct {
Metadata Metadata `json:"metadata"`
Entity AccountEntity `json:"entity"`
}

type AccountEntity struct {
BillingCountryCode string `json:"billing_country_code"`
BluemixSubscriptions []BluemixSubscription `json:"bluemix_subscriptions"`
ConfigurationID *string `json:"configuration_id"` // Using pointer to handle null
CountryCode string `json:"country_code"`
CurrencyCode string `json:"currency_code"`
CurrentBillingSystem string `json:"current_billing_system"`
CustomerID string `json:"customer_id"`
IsIBMer bool `json:"isIBMer"`
Linkages []AccountLinkage `json:"linkages"`
Name string `json:"name"`
OfferTemplate string `json:"offer_template"`
Onboarded int `json:"onboarded"`
OrganizationsRegion []OrganizationsRegion `json:"organizations_region"`
Origin string `json:"origin"`
Owner string `json:"owner"`
OwnerIAMID string `json:"owner_iam_id"`
OwnerUniqueID string `json:"owner_unique_id"`
OwnerUserID string `json:"owner_userid"`
State string `json:"state"`
SubscriptionID string `json:"subscription_id"`
Tags []interface{} `json:"tags"` // Using interface{} since type is not specified
TeamDirectoryEnabled bool `json:"team_directory_enabled"`
TermsAndConditions TermsAndConditions `json:"terms_and_conditions"`
Type string `json:"type"`
}

type BluemixSubscription struct {
BillToContact string `json:"bill_to_contact"`
BillingSystem string `json:"billing_system"`
CatalogID string `json:"catalog_id"`
CurrentStateTimestamp time.Time `json:"current_state_timestamp"`
DistributionChannel string `json:"distribution_channel"`
History []History `json:"history"`
OrderID string `json:"order_id"`
PartNumber string `json:"part_number"`
PaygPendingTimestamp time.Time `json:"payg_pending_timestamp"`
PaymentMethod PaymentMethod `json:"payment_method"`
SoftlayerAccountID string `json:"softlayer_account_id"`
SoldToContact string `json:"sold_to_contact"`
State string `json:"state"`
SubscriptionTags []interface{} `json:"subscriptionTags"`
SubscriptionID string `json:"subscription_id"`
Type string `json:"type"`
}

type History struct {
BillingCountryCode string `json:"billingCountryCode"`
BillingSystem string `json:"billingSystem"`
CountryCode string `json:"countryCode"`
CurrencyCode string `json:"currencyCode"`
EndTime time.Time `json:"endTime"`
StartTime time.Time `json:"startTime"`
State string `json:"state"`
Type string `json:"type"`
BillToContact *string `json:"billToContact,omitempty"`
OrderId *string `json:"orderId,omitempty"`
PaymentMethodType *string `json:"paymentMethodType,omitempty"`
SoldToContact *string `json:"soldToContact,omitempty"`
StateEndComments *string `json:"stateEndComments,omitempty"`
StateEndedBy *string `json:"stateEndedBy,omitempty"`
WalletId *string `json:"walletId,omitempty"`
}

type PaymentMethod struct {
Ended *string `json:"ended"` // Using pointer to handle null
Started time.Time `json:"started"`
Type string `json:"type"`
WalletID string `json:"wallet_id"`
}

type AccountLinkage struct {
Origin string `json:"origin"`
State string `json:"state"`
}

type OrganizationsRegion struct {
GUID string `json:"guid"`
Region string `json:"region"`
}

type TermsAndConditions struct {
Accepted bool `json:"accepted"`
Required bool `json:"required"`
Timestamp time.Time `json:"timestamp"`
}

type Metadata struct {
CreatedAt time.Time `json:"created_at"`
GUID string `json:"guid"`
UpdateComments string `json:"update_comments"`
UpdatedAt time.Time `json:"updated_at"`
UpdatedBy string `json:"updated_by"`
URL string `json:"url"`
}

0 comments on commit 156c0e7

Please sign in to comment.