Skip to content

Commit f3c12b0

Browse files
Akash-PatilRevanthTanneeru
authored andcommitted
Added get site command
Refactored get site code Implement registration schema commands in LoginRadius CLI Co-authored-by: RevanthTanneeru <revanthtanneeru@LRIN-ENG-36.local>
1 parent 945c761 commit f3c12b0

10 files changed

Lines changed: 434 additions & 4 deletions

File tree

api/deployment.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,45 @@ type HostedPageResponse struct {
6060
} `json:"Pages"`
6161
}
6262

63+
type CoreAppData struct {
64+
Apps struct {
65+
Data []struct {
66+
Appname string `json:"AppName"`
67+
Customername interface{} `json:"CustomerName"`
68+
Webtechnology int `json:"WebTechnology"`
69+
Domain string `json:"Domain"`
70+
Callbackurl string `json:"CallbackUrl"`
71+
Devdomain string `json:"DevDomain"`
72+
Ismobile bool `json:"IsMobile"`
73+
Appid int `json:"AppId"`
74+
Key string `json:"Key"`
75+
Secret string `json:"Secret"`
76+
Role string `json:"Role"`
77+
Iswelcomeemailenabled bool `json:"IsWelcomeEmailEnabled"`
78+
Ishttps bool `json:"Ishttps"`
79+
Interfaceid int `json:"InterfaceId"`
80+
Recurlyaccountcode interface{} `json:"RecurlyAccountCode"`
81+
Userlimit int `json:"UserLimit"`
82+
Domainlimit int `json:"DomainLimit"`
83+
Datecreated time.Time `json:"DateCreated"`
84+
Datemodified time.Time `json:"DateModified"`
85+
Status bool `json:"Status"`
86+
Profilephoto string `json:"ProfilePhoto"`
87+
Apiversion string `json:"ApiVersion"`
88+
Israasenabled bool `json:"IsRaasEnabled"`
89+
Privacypolicy interface{} `json:"PrivacyPolicy"`
90+
Termsofservice interface{} `json:"TermsOfService"`
91+
Ownerid string `json:"OwnerId"`
92+
Productplan struct {
93+
Name string `json:"Name"`
94+
Expirytime time.Time `json:"ExpiryTime"`
95+
Billingcycle interface{} `json:"BillingCycle"`
96+
Fromdate time.Time `json:"FromDate"`
97+
} `json:"ProductPlan"`
98+
} `json:"Data"`
99+
} `json:"apps"`
100+
}
101+
63102
func GetSites() (*SitesReponse, error) {
64103

65104
url := conf.AdminConsoleAPIDomain + "/deployment/sites?"
@@ -90,3 +129,17 @@ func GetPage() (*HostedPageResponse, error) {
90129
}
91130
return &resultResp, nil
92131
}
132+
133+
func AppInfo() (*CoreAppData, error) {
134+
coreAppData := conf.AdminConsoleAPIDomain + "/auth/core-app-data?"
135+
AppData, err := request.Rest(http.MethodGet, coreAppData, nil, "")
136+
if err != nil {
137+
return nil, err
138+
}
139+
var App CoreAppData
140+
err = json.Unmarshal(AppData, &App)
141+
if err != nil {
142+
return nil, err
143+
}
144+
return &App, nil
145+
}

cmd/delete/delete.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package delete
33
import (
44
"github.com/loginradius/lr-cli/cmd/delete/account"
55
"github.com/loginradius/lr-cli/cmd/delete/domain"
6+
"github.com/loginradius/lr-cli/cmd/delete/schema"
67
"github.com/loginradius/lr-cli/cmd/delete/social"
78

89
"github.com/spf13/cobra"
@@ -25,5 +26,8 @@ func NewdeleteCmd() *cobra.Command {
2526
accountCmd := account.NewaccountCmd()
2627
cmd.AddCommand(accountCmd)
2728

29+
schemaCmd := schema.NewschemaCmd()
30+
cmd.AddCommand(schemaCmd)
31+
2832
return cmd
2933
}

cmd/delete/schema/schema.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package schema
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"fmt"
7+
"net/http"
8+
9+
"github.com/MakeNowJust/heredoc"
10+
"github.com/loginradius/lr-cli/api"
11+
"github.com/loginradius/lr-cli/request"
12+
13+
"github.com/loginradius/lr-cli/cmdutil"
14+
"github.com/loginradius/lr-cli/config"
15+
16+
"github.com/spf13/cobra"
17+
)
18+
19+
var fieldName string
20+
21+
type Schema struct {
22+
Display string `json:"Display"`
23+
Enabled bool `json:"Enabled"`
24+
IsMandatory bool `json:"IsMandatory"`
25+
Parent string `json:"Parent"`
26+
ParentDataSource string `json:"ParentDataSource"`
27+
Permission string `json:"Permission"`
28+
Name string `json:"name"`
29+
Rules string `json:"rules"`
30+
Status string `json:"status"`
31+
Type string `json:"type"`
32+
}
33+
34+
type Result struct {
35+
Data []Schema `json:"Data"`
36+
}
37+
38+
func NewschemaCmd() *cobra.Command {
39+
40+
cmd := &cobra.Command{
41+
Use: "schema",
42+
Short: "delete schema",
43+
Long: `This commmand deletes schema fields`,
44+
Example: heredoc.Doc(`$ lr delete schema --fieldname <fieldname>`),
45+
RunE: func(cmd *cobra.Command, args []string) error {
46+
if fieldName == "" {
47+
return &cmdutil.FlagError{Err: errors.New("`fieldname` is required argument")}
48+
}
49+
if fieldName == "emailid" || fieldName == "password" {
50+
return &cmdutil.FlagError{Err: errors.New("EmailId and Password fields cannot be deleted")}
51+
}
52+
return delete(fieldName)
53+
54+
},
55+
}
56+
57+
fl := cmd.Flags()
58+
fl.StringVarP(&fieldName, "fieldname", "f", "", "field name")
59+
60+
return cmd
61+
}
62+
63+
func delete(Field string) error {
64+
res, err2 := api.GetSites()
65+
if (res.Productplan) != res.Productplan || res.Productplan.Name == "free" {
66+
fmt.Println("Kindly Upgrade the plan to enable this command for your app")
67+
return nil
68+
}
69+
if err2 != nil {
70+
return err2
71+
}
72+
var url string
73+
var url1 string
74+
conf := config.GetInstance()
75+
76+
url1 = conf.AdminConsoleAPIDomain + "/platform-configuration/registration-form-settings?"
77+
var resultResp1 Result
78+
resp1, err1 := request.Rest(http.MethodGet, url1, nil, "")
79+
err1 = json.Unmarshal(resp1, &resultResp1)
80+
if err1 != nil {
81+
return err1
82+
}
83+
for i := 0; i < len(resultResp1.Data); i++ {
84+
if resultResp1.Data[i].Name == Field {
85+
resultResp1.Data[i].Enabled = false
86+
}
87+
}
88+
body, _ := json.Marshal(resultResp1)
89+
url = conf.AdminConsoleAPIDomain + "/platform-configuration/default-fields?"
90+
91+
var resultResp Result
92+
resp, err := request.Rest(http.MethodPost, url, nil, string(body))
93+
err = json.Unmarshal(resp, &resultResp)
94+
if err != nil {
95+
return err
96+
}
97+
fmt.Println("The field has been sucessfully deleted")
98+
return nil
99+
}

cmd/get/get.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"github.com/loginradius/lr-cli/cmd/get/accountPassword"
66
"github.com/loginradius/lr-cli/cmd/get/config"
77
"github.com/loginradius/lr-cli/cmd/get/profiles"
8+
"github.com/loginradius/lr-cli/cmd/get/schema"
9+
"github.com/loginradius/lr-cli/cmd/get/site"
810

911
"github.com/loginradius/lr-cli/cmd/get/domain"
1012
"github.com/loginradius/lr-cli/cmd/get/email"
@@ -23,6 +25,9 @@ func NewGetCmd() *cobra.Command {
2325
Long: `This commmand acts as a base command for get subcommands`,
2426
}
2527

28+
siteCmd := site.NewSiteCmd()
29+
cmd.AddCommand(siteCmd)
30+
2631
themeCmd := theme.NewThemeCmd()
2732
cmd.AddCommand(themeCmd)
2833

@@ -49,5 +54,8 @@ func NewGetCmd() *cobra.Command {
4954

5055
profilesCmd := profiles.NewprofilesCmd()
5156
cmd.AddCommand(profilesCmd)
57+
58+
schemaCmd := schema.NewschemaCmd()
59+
cmd.AddCommand(schemaCmd)
5260
return cmd
5361
}

cmd/get/schema/schema.go

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package schema
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
"time"
8+
9+
"github.com/MakeNowJust/heredoc"
10+
"github.com/loginradius/lr-cli/api"
11+
"github.com/loginradius/lr-cli/config"
12+
"github.com/loginradius/lr-cli/request"
13+
14+
"github.com/spf13/cobra"
15+
)
16+
17+
var temp string
18+
19+
type Schema struct {
20+
Display string `json:"Display"`
21+
Enabled bool `json:"Enabled"`
22+
IsMandatory bool `json:"IsMandatory"`
23+
Parent string `json:"Parent"`
24+
ParentDataSource string `json:"ParentDataSource"`
25+
Permission string `json:"Permission"`
26+
Name string `json:"name"`
27+
Rules string `json:"rules"`
28+
Status string `json:"status"`
29+
Type string `json:"type"`
30+
}
31+
type schemaStr struct {
32+
Data []Schema `json:"Data"`
33+
}
34+
35+
var url string
36+
37+
func NewschemaCmd() *cobra.Command {
38+
39+
cmd := &cobra.Command{
40+
Use: "schema",
41+
Short: "get schema config",
42+
Long: `This commmand lists schema config`,
43+
Example: heredoc.Doc(`$ lr get schema`),
44+
RunE: func(cmd *cobra.Command, args []string) error {
45+
fstatus, _ := cmd.Flags().GetBool("all")
46+
if fstatus {
47+
temp = "all"
48+
}
49+
fstatus1, _ := cmd.Flags().GetBool("active")
50+
if fstatus1 {
51+
temp = "active"
52+
}
53+
return get()
54+
55+
},
56+
}
57+
fl := cmd.Flags()
58+
fl.BoolP("all", "a", false, "option to get all fields")
59+
fl.BoolP("active", "c", false, "option to get active fields")
60+
61+
return cmd
62+
}
63+
64+
func get() error {
65+
res, err1 := api.GetSites()
66+
var re struct {
67+
Name string "json:\"Name\""
68+
Expirytime time.Time "json:\"ExpiryTime\""
69+
Billingcycle interface{} "json:\"BillingCycle\""
70+
Fromdate interface{} "json:\"FromDate\""
71+
}
72+
if res.Productplan == re || res.Productplan.Name == "free" {
73+
fmt.Println("Kindly Upgrade the plan to enable this command for your app")
74+
return nil
75+
}
76+
if err1 != nil {
77+
return err1
78+
}
79+
conf := config.GetInstance()
80+
if temp == "active" {
81+
url = conf.AdminConsoleAPIDomain + "/platform-configuration/registration-form-settings?"
82+
}
83+
if temp == "all" {
84+
url = conf.AdminConsoleAPIDomain + "/platform-configuration/platform-registration-fields?"
85+
}
86+
87+
var resultResp schemaStr
88+
resp, err := request.Rest(http.MethodGet, url, nil, "")
89+
90+
if err != nil {
91+
return err
92+
}
93+
94+
err = json.Unmarshal(resp, &resultResp)
95+
if err != nil {
96+
return err
97+
}
98+
var j = 0
99+
var temp1 []int
100+
fmt.Println("Select one of the fields to get the schema")
101+
for i := 0; i < len(resultResp.Data); i++ {
102+
if resultResp.Data[i].Parent == "" {
103+
fmt.Print(j + 1)
104+
fmt.Println("." + resultResp.Data[i].Display)
105+
j++
106+
temp1 = append(temp1, i)
107+
}
108+
}
109+
var num int
110+
111+
// Taking input from user
112+
fmt.Scanln(&num)
113+
for 1 > num || num > len(temp1) {
114+
fmt.Println("Please select a number from 1 to " + fmt.Sprint(len(temp1)))
115+
fmt.Scanln(&num)
116+
}
117+
if resultResp.Data[temp1[num-1]].Parent == "" {
118+
fmt.Println("Display: " + resultResp.Data[temp1[num-1]].Display)
119+
fmt.Println("Enabled: ", resultResp.Data[temp1[num-1]].Enabled)
120+
fmt.Println("IsMandatory: ", resultResp.Data[temp1[num-1]].IsMandatory)
121+
fmt.Println("Parent: ", resultResp.Data[temp1[num-1]].Parent)
122+
fmt.Println("ParentDataSource: ", resultResp.Data[temp1[num-1]].ParentDataSource)
123+
fmt.Println("Permission: ", resultResp.Data[temp1[num-1]].Permission)
124+
fmt.Println("Name: ", resultResp.Data[temp1[num-1]].Name)
125+
fmt.Println("Rules: ", resultResp.Data[temp1[num-1]].Rules)
126+
fmt.Println("Status: ", resultResp.Data[temp1[num-1]].Status)
127+
fmt.Println("Type: ", resultResp.Data[temp1[num-1]].Type)
128+
129+
}
130+
131+
return nil
132+
}

0 commit comments

Comments
 (0)