generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 13
/
facade_accounts_subaccount.go
131 lines (102 loc) · 5.3 KB
/
facade_accounts_subaccount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package btpcli
import (
"context"
"github.com/SAP/terraform-provider-btp/internal/btpcli/types/cis"
"github.com/SAP/terraform-provider-btp/internal/btpcli/types/saas_manager_service"
"github.com/SAP/terraform-provider-btp/internal/tfutils"
)
func newAccountsSubaccountFacade(cliClient *v2Client) accountsSubaccountFacade {
return accountsSubaccountFacade{cliClient: cliClient}
}
type accountsSubaccountFacade struct {
cliClient *v2Client
}
func (f *accountsSubaccountFacade) getCommand() string {
return "accounts/subaccount"
}
func (f *accountsSubaccountFacade) List(ctx context.Context, labelsFilter string) (cis.ResponseCollectionSubaccountResponseObject, CommandResponse, error) {
params := map[string]string{
"globalAccount": f.cliClient.GetGlobalAccountSubdomain(),
}
if len(labelsFilter) > 0 {
params["labelsFilter"] = labelsFilter
}
return doExecute[cis.ResponseCollectionSubaccountResponseObject](f.cliClient, ctx, NewListRequest(f.getCommand(), params))
}
func (f *accountsSubaccountFacade) Get(ctx context.Context, subaccountId string) (cis.SubaccountResponseObject, CommandResponse, error) {
return doExecute[cis.SubaccountResponseObject](f.cliClient, ctx, NewGetRequest(f.getCommand(), map[string]string{
"globalAccount": f.cliClient.GetGlobalAccountSubdomain(),
"subaccount": subaccountId,
}))
}
type SubaccountCreateInput struct { // TODO support all options
BetaEnabled bool `btpcli:"betaEnabled"`
Description string `btpcli:"description"`
Directory string `btpcli:"directoryID"`
DisplayName string `btpcli:"displayName"`
Labels map[string][]string `btpcli:"labels"`
Region string `btpcli:"region"`
Subdomain string `btpcli:"subdomain"`
UsedForProduction string `btpcli:"usedForProduction"`
Globalaccount string `btpcli:"globalAccount"`
//SubaccountAdmins string `json:"subaccountAdmins"`
}
type SubaccountUpdateInput struct {
BetaEnabled bool `btpcli:"betaEnabled"`
Description string `btpcli:"description"`
Directory string `btpcli:"directoryID"`
DisplayName string `btpcli:"displayName"`
Labels map[string][]string `btpcli:"labels"`
SubaccountId string `btpcli:"subaccount"`
UsedForProduction string `btpcli:"usedForProduction"`
Globalaccount string `btpcli:"globalAccount"`
}
func (f *accountsSubaccountFacade) Create(ctx context.Context, args *SubaccountCreateInput) (cis.SubaccountResponseObject, CommandResponse, error) {
args.Globalaccount = f.cliClient.GetGlobalAccountSubdomain()
params, err := tfutils.ToBTPCLIParamsMap(args)
if err != nil {
return cis.SubaccountResponseObject{}, CommandResponse{}, err
}
return doExecute[cis.SubaccountResponseObject](f.cliClient, ctx, NewCreateRequest(f.getCommand(), params))
}
func (f *accountsSubaccountFacade) Update(ctx context.Context, args *SubaccountUpdateInput) (cis.SubaccountResponseObject, CommandResponse, error) { // TODO switch to object
args.Globalaccount = f.cliClient.GetGlobalAccountSubdomain()
// Mapping of all params except for usedForProduction
params, err := tfutils.ToBTPCLIParamsMap(args)
if err != nil {
return cis.SubaccountResponseObject{}, CommandResponse{}, err
}
return doExecute[cis.SubaccountResponseObject](f.cliClient, ctx, NewUpdateRequest(f.getCommand(), params))
}
func (f *accountsSubaccountFacade) Delete(ctx context.Context, subaccountId string, directoryId string) (cis.SubaccountResponseObject, CommandResponse, error) {
requestArgs := map[string]string{
"globalAccount": f.cliClient.GetGlobalAccountSubdomain(),
"subaccount": subaccountId,
"confirm": "true",
"forceDelete": "true",
}
if len(directoryId) > 0 {
//if the parent of the subaccount is a managed directory, the directoryID must be set to make sure the right authorizations are validated
requestArgs["directoryID"] = directoryId
}
return doExecute[cis.SubaccountResponseObject](f.cliClient, ctx, NewDeleteRequest(f.getCommand(), requestArgs))
}
func (f *accountsSubaccountFacade) Subscribe(ctx context.Context, subaccountId string, appName string, planName string, parameters string) (saas_manager_service.SubscriptionAssignmentResponseObject, CommandResponse, error) {
commandOptions := map[string]string{
"subaccount": subaccountId,
"appName": appName,
"subscriptionParams": parameters,
}
// The plan name can be empty in case of subscription hosted in the same account. In this case the plan name is not required and must not be transferred to the API call.
if len(planName) > 0 {
commandOptions["planName"] = planName
}
return doExecute[saas_manager_service.SubscriptionAssignmentResponseObject](f.cliClient, ctx, NewSubscribeRequest(f.getCommand(), commandOptions))
}
func (f *accountsSubaccountFacade) Unsubscribe(ctx context.Context, subaccountId string, appName string) (saas_manager_service.SubscriptionAssignmentResponseObject, CommandResponse, error) {
return doExecute[saas_manager_service.SubscriptionAssignmentResponseObject](f.cliClient, ctx, NewUnsubscribeRequest(f.getCommand(), map[string]string{
"subaccount": subaccountId,
"appName": appName,
"confirm": "true",
}))
}