Skip to content

Commit 9556d58

Browse files
authored
Merge pull request #79 from muskansoninmh/major_cli_bugs
resolved all the bugs in cli
2 parents bc7ad18 + bacfa69 commit 9556d58

File tree

17 files changed

+216
-67
lines changed

17 files changed

+216
-67
lines changed

api/auth.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func SitesBasic(tokens *SitesToken) error {
131131
if err != nil {
132132
return err
133133
}
134-
_, err = GetAppsInfo()
134+
_,_, err = GetAppsInfo()
135135
if err != nil {
136136
return err
137137
}
@@ -140,19 +140,20 @@ func SitesBasic(tokens *SitesToken) error {
140140

141141
}
142142

143-
func GetAppsInfo() (map[int64]SitesReponse, error) {
143+
func GetAppsInfo() (map[int64]SitesReponse,map[int64]SharedSitesReponse, error) {
144144
var Apps CoreAppData
145145

146146
coreAppData := conf.AdminConsoleAPIDomain + "/auth/core-app-data?"
147147
data, err := request.Rest(http.MethodGet, coreAppData, nil, "")
148148
if err != nil {
149-
return nil, err
149+
return nil,nil, err
150150
}
151151
err = json.Unmarshal(data, &Apps)
152152
if err != nil {
153-
return nil, err
153+
return nil,nil, err
154154
}
155-
return storeSiteInfo(Apps), nil
155+
apps, sharedApps := storeSiteInfo(Apps)
156+
return apps,sharedApps, nil
156157
}
157158

158159
func CurrentID() (int64, error) {
@@ -203,12 +204,17 @@ func IsPasswordLessEnabled(features FeatureSchema) bool {
203204
return false
204205
}
205206

206-
func storeSiteInfo(data CoreAppData) map[int64]SitesReponse {
207+
func storeSiteInfo(data CoreAppData) (map[int64]SitesReponse, map[int64]SharedSitesReponse) {
207208
siteInfo := make(map[int64]SitesReponse, len(data.Apps.Data))
209+
sharedsiteInfo := make(map[int64]SharedSitesReponse, len(data.Apps.Data))
208210
for _, app := range data.Apps.Data {
209211
siteInfo[app.Appid] = app
210212
}
211213
obj, _ := json.Marshal(siteInfo)
214+
for _, app := range data.SharedApps.Data {
215+
sharedsiteInfo[app.Appid] = app
216+
}
217+
obj, _ = json.Marshal(sharedsiteInfo)
212218
cmdutil.WriteFile("siteInfo.json", obj)
213219
currentId, err := CurrentID()
214220
if err == nil {
@@ -218,7 +224,7 @@ func storeSiteInfo(data CoreAppData) map[int64]SitesReponse {
218224
cmdutil.WriteFile("currentSite.json", obj)
219225
}
220226
}
221-
return siteInfo
227+
return siteInfo,sharedsiteInfo
222228
}
223229

224230
func UpdatePhoneLogin(feature string, status bool) (*FeatureSchema, error) {

api/deployment.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ type SitesReponse struct {
4949
} `json:"ProductPlan"`
5050
}
5151

52+
type SharedSitesReponse struct {
53+
Appname string `json:"AppName"`
54+
Domain string `json:"Domain"`
55+
Appid int64 `json:"AppId"`
56+
AppKey string `json:"ApiKey"`
57+
AppSecret string `json:"ApiSecret"`
58+
Role []string `json:"Role"`
59+
AdditionalPermissions []string `json:"AdditionalPermissions"`
60+
Recurlyaccountcode *string `json:"RecurlyAccountCode"`
61+
Userlimit int `json:"UserLimit"`
62+
Domainlimit int `json:"DomainLimit"`
63+
Apiversion string `json:"ApiVersion"`
64+
Israasenabled bool `json:"IsRaasEnabled"`
65+
Ownerid string `json:"OwnerId"`
66+
Productplan *struct {
67+
Name string `json:"Name"`
68+
Expirytime time.Time `json:"ExpiryTime"`
69+
Billingcycle interface{} `json:"BillingCycle"`
70+
Fromdate interface{} `json:"FromDate"`
71+
} `json:"ProductPlan"`
72+
}
73+
5274
type HostedPageResponse struct {
5375
Pages []struct {
5476
Pagetype string `json:"PageType"`
@@ -81,6 +103,9 @@ type CoreAppData struct {
81103
Apps struct {
82104
Data []SitesReponse `json:"Data"`
83105
} `json:"apps"`
106+
SharedApps struct {
107+
Data []SharedSitesReponse `json:"Data"`
108+
} `json:"sharedApps"`
84109
}
85110

86111
type SmtpConfigSchema struct {

api/platformConfiguration.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@ func GetRegistrationFields() (map[string]Schema, error) {
208208
provMap := make(map[string]Schema, len(resultResp.Data))
209209

210210
for _ ,value := range resultResp.Data {
211-
provMap[strings.ToLower(value.Name)] = value
211+
if !strings.Contains(value.Name, "cf") {
212+
provMap[strings.ToLower(value.Name)] = value
213+
} else {
214+
provMap[value.Name] = value
215+
}
212216
}
213217
return provMap, nil
214218
}

cmd/add/hooks/hooks.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"errors"
8+
"strings"
79

810
"github.com/AlecAivazis/survey/v2"
911
"github.com/MakeNowJust/heredoc"
@@ -66,13 +68,12 @@ func addHooks() error {
6668
// }
6769
// }
6870

69-
checkInput := input()
71+
checkInput,err := input()
7072
if !checkInput {
71-
fmt.Println("Please enter the input paramaters properly.")
72-
return nil
73+
return err
7374
}
7475

75-
err := add()
76+
err = add()
7677
if err != nil {
7778
return err
7879
}
@@ -81,28 +82,42 @@ func addHooks() error {
8182
return nil
8283
}
8384

84-
func input() bool {
85+
func input() (bool, error) {
86+
Hooks, err := api.Hooks(http.MethodGet, "")
87+
if err != nil {
88+
return false, err
89+
}
8590
prompt.SurveyAskOne(&survey.Input{
8691
Message: "Enter Name:",
8792
}, &Name, survey.WithValidator(survey.Required))
88-
93+
if strings.TrimSpace(Name) == "" {
94+
return false, errors.New("Webhook Name is required")
95+
}
96+
for _,v := range Hooks.Data {
97+
if v.Name == Name {
98+
return false, errors.New("Webhook name exists. Please use a different name.")
99+
}
100+
}
89101
var options = Events
90102

91103
var eventChoice int
92-
err := prompt.SurveyAskOne(&survey.Select{
104+
err = prompt.SurveyAskOne(&survey.Select{
93105
Message: "Select a plan",
94106
Options: options,
95107
}, &eventChoice)
96108
if err != nil {
97-
return false
109+
return false, err
98110
}
99111
Event = options[eventChoice]
100112

101113
prompt.SurveyAskOne(&survey.Input{
102114
Message: "Enter TargetUrl: ",
103115
}, &TargetUrl, survey.WithValidator(survey.Required))
116+
if strings.TrimSpace(TargetUrl) == "" {
117+
return false, errors.New("Webhook Target URL is required")
118+
}
104119

105-
return true
120+
return true, nil
106121

107122
}
108123

cmd/add/site/site.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func add() error {
8787
if err != nil {
8888
return err
8989
}
90-
appInfo, err := api.GetAppsInfo()
90+
appInfo,_, err := api.GetAppsInfo()
9191
if err != nil {
9292
return err
9393
}

cmd/add/social/social.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ func add1() error {
6767
if err != nil {
6868
return err
6969
}
70-
provConfig, ok := allProv[strings.ToLower(providers[num])]
70+
var providerName string
71+
if strings.Contains(providers[num], " ") {
72+
providerName = strings.Join(strings.Split(providers[num], " "), "")
73+
} else {
74+
providerName = providers[num]
75+
}
76+
provConfig, ok := allProv[strings.ToLower(providerName)]
7177
if !ok {
7278
return errors.New("Configuration for the selected provider not found.")
7379
}
@@ -82,7 +88,9 @@ func add1() error {
8288
prompt.SurveyAskOne(&survey.Input{
8389
Message: val.Display + ":",
8490
}, &promptRes, survey.WithValidator(survey.Required))
85-
91+
if strings.TrimSpace(promptRes) == "" {
92+
return errors.New(val.Display + " is required")
93+
}
8694
field.SetString(promptRes)
8795
}
8896
addProvObj.Data[0].Provider = provConfig.Name

cmd/delete/domain/domain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewdomainCmd() *cobra.Command {
3030
Short: "Deletes a domain",
3131
Long: `Use this command to remove the whitelisted domain from your app.`,
3232
Example: heredoc.Doc(`$ lr delete domain --domain <domain>
33-
<doamin> is now removed from whitelisted domain."
33+
<domain> is now removed from whitelisted domain."
3434
`),
3535
RunE: func(cmd *cobra.Command, args []string) error {
3636
if opts.Domain == "" {

cmd/delete/site/site.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewSiteCmd() *cobra.Command {
4646
}
4747

4848
func deleteSite() error {
49-
siteInfo, err := api.GetAppsInfo()
49+
siteInfo,_, err := api.GetAppsInfo()
5050
if err != nil {
5151
return err
5252
}
@@ -112,7 +112,7 @@ func delete(appInfo api.SitesReponse) (bool, error) {
112112
if err != nil {
113113
return false, err
114114
}
115-
_, err = api.GetAppsInfo()
115+
_,_, err = api.GetAppsInfo()
116116
if err != nil {
117117
return false, err
118118
}

cmd/delete/sott/sott.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"errors"
78

89
"github.com/MakeNowJust/heredoc"
10+
"github.com/loginradius/lr-cli/cmdutil"
911
"github.com/loginradius/lr-cli/api"
1012
"github.com/loginradius/lr-cli/config"
1113
"github.com/loginradius/lr-cli/prompt"
@@ -37,6 +39,9 @@ func NewSottCmd() *cobra.Command {
3739
3840
`),
3941
RunE: func(cmd *cobra.Command, args []string) error {
42+
if token == "" && !*all {
43+
return &cmdutil.FlagError{Err: errors.New("`token` is required argument")}
44+
}
4045
return deleteSott()
4146

4247
},

cmd/get/schema/schema.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ func NewschemaCmd() *cobra.Command {
2929
| country | Country | string | false |
3030
| firstname | First Name | string | false |
3131
+-----------+---------------+----------+---------+
32-
+---------------+----------+---------+
33-
| CUSTOM FIELDS | TYPE | ENABLED |
34-
+---------------+----------+---------+
35-
| MyCF | string | false |
36-
+---------------+----------+---------+
32+
+-------------------+-----------------------+---------+--------+
33+
| CUSTOM FIELD NAME | CUSTOM FIELD DISPLAY | TYPE | ENABLED |
34+
+-------------------+-----------------------+---------+--------+
35+
| cf_MyCF | MyCF | string | false |
36+
+-------------------+-----------------------+---------+--------+
3737
`),
3838
RunE: func(cmd *cobra.Command, args []string) error {
3939
return get()
@@ -67,7 +67,12 @@ func get() error {
6767
if Type == "multi" {
6868
Type = "checkbox"
6969
}
70-
data = append(data, []string{k, v.Display, Type, enabled})
70+
var displayName string
71+
displayName = activeRegField[k].Display
72+
if displayName == "" {
73+
displayName = v.Display
74+
}
75+
data = append(data, []string{k, displayName, Type, enabled})
7176
}
7277
sort.SliceStable(data, func(i, j int) bool {
7378
return data[i][3] == "true"
@@ -86,18 +91,24 @@ func get() error {
8691
if len(customFields.Data) > 0 {
8792
for _, v := range customFields.Data {
8893
enabled := "false"
89-
_, ok := activeRegField["cf_" + v.Display]
94+
_, ok := activeRegField["cf_" + v.Key]
9095
if ok {
9196
enabled = "true"
9297
}
93-
Type := activeRegField["cf_" + v.Display].Type
94-
cfTable.Append([]string{v.Display, Type,enabled})
98+
Type := activeRegField["cf_" + v.Key].Type
99+
100+
var displayName string
101+
displayName = activeRegField["cf_" + v.Key].Display
102+
if displayName == "" {
103+
displayName = v.Display
104+
}
105+
cfTable.Append([]string{"cf_" + v.Key,displayName, Type,enabled})
95106
}
96107
} else {
97108
cfTable.Append([]string{"No Custom Fields"})
98109
cfTable.SetCaption(true, "Use command `lr add custom-field` to add the Custom Field")
99110
}
100-
cfTable.SetHeader([]string{"Custom Fields", "Type", "Enabled"})
111+
cfTable.SetHeader([]string{"Custom Field Name","Custom Field Display", "Type", "Enabled"})
101112
cfTable.Render()
102113

103114
return nil

0 commit comments

Comments
 (0)