Skip to content

Commit 5b7c9b7

Browse files
authored
Merge pull request #85 from sagarPujariLr/develop
It has all the updated code - IP Access Restriction, Permissions, Default Theme
2 parents fc40948 + 98aa222 commit 5b7c9b7

53 files changed

Lines changed: 1153 additions & 168 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/account.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ type SitesToken struct {
1818
XToken string `json:"xtoken"`
1919
}
2020

21-
func SetSites(appid int64) (*SitesToken, error) {
22-
switchapp := conf.AdminConsoleAPIDomain + "/account/switchapp?appid=" + strconv.FormatInt(appid, 10)
21+
func SetSites(appid int64, owned bool) (*SitesToken, error) {
22+
var api string
23+
if (owned){
24+
api = "/account/switchapp?appid="
25+
} else {
26+
api = "/account/switchsharedsite?appid="
27+
}
28+
switchapp := conf.AdminConsoleAPIDomain + api + strconv.FormatInt(appid, 10)
2329
switchResp, err := request.Rest(http.MethodGet, switchapp, nil, "")
2430
var switchRespObj SitesToken
2531
err = json.Unmarshal(switchResp, &switchRespObj)

api/auth.go

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"net/http"
88
"time"
9+
"reflect"
910

1011
"github.com/loginradius/lr-cli/cmdutil"
1112
"github.com/loginradius/lr-cli/config"
@@ -20,7 +21,7 @@ type LoginResponse struct {
2021
AppName string `json:"app_name"`
2122
Authenticated bool `json:"authenticated"`
2223
NoOfLogins int32 `json:"no_of_logins"`
23-
PlanDetails interface{} `json"plan_detail"`
24+
PlanDetails interface{} `json:"plan_detail"`
2425
XSign string `json:"xsign"`
2526
XToken string `json:"xtoken"`
2627
}
@@ -44,6 +45,28 @@ type Feature struct {
4445
Status bool `json:"status"`
4546
}
4647

48+
type PermissionResponse struct {
49+
Permissions Permission `json:"permissions"`
50+
}
51+
52+
type Permission struct {
53+
API_AdminConfiguration bool `json:"API_AdminConfiguration"`
54+
API_EditConfiguration bool `json:"API_EditConfiguration"`
55+
API_EditCredentials bool `json:"API_EditCredentials"`
56+
API_EditThirdPartyCredentials bool `json:"API_EditThirdPartyCredentials"`
57+
API_ViewCredentials bool `json:"API_ViewCredentials"`
58+
UserManagement_Admin bool `json:"UserManagement_Admin"`
59+
API_ViewConfiguration bool `json:"API_ViewConfiguration"`
60+
API_ViewThirdPartyCredentials bool `json:"API_ViewThirdPartyCredentials"`
61+
ThirdPartyIntegration_View bool `json:"ThirdPartyIntegration_View"`
62+
UserManagement_View bool `json:"UserManagement_View"`
63+
SecurityPolicy_View bool `json:"SecurityPolicy_View"`
64+
API_AdminThirdPartyCredentials bool `json:"API_AdminThirdPartyCredentials"`
65+
ThirdPartyIntegration_Admin bool `json:"ThirdPartyIntegration_Admin"`
66+
SecurityPolicy_Admin bool `json:"SecurityPolicy_Admin"`
67+
SecurityPolicy_Edit bool `json:"SecurityPolicy_Edit"`
68+
}
69+
4770
func AuthLogin(params LoginOpts) (*LoginResponse, error) {
4871

4972
var resObj LoginResponse
@@ -204,6 +227,15 @@ func IsPasswordLessEnabled(features FeatureSchema) bool {
204227
return false
205228
}
206229

230+
func IsIPAutthorizationEnabled(features FeatureSchema) bool {
231+
for _, val := range features.Data {
232+
if val.Feature == "ip_authorization_enabled" && val.Status {
233+
return true
234+
}
235+
}
236+
return false
237+
}
238+
207239
func storeSiteInfo(data CoreAppData) (map[int64]SitesReponse, map[int64]SharedSitesReponse) {
208240
siteInfo := make(map[int64]SitesReponse, len(data.Apps.Data))
209241
sharedsiteInfo := make(map[int64]SharedSitesReponse, len(data.Apps.Data))
@@ -219,9 +251,15 @@ func storeSiteInfo(data CoreAppData) (map[int64]SitesReponse, map[int64]SharedSi
219251
currentId, err := CurrentID()
220252
if err == nil {
221253
site, ok := siteInfo[currentId]
254+
sharedsite, sharedok := sharedsiteInfo[currentId]
222255
if ok {
223-
obj, _ := json.Marshal(site)
224-
cmdutil.WriteFile("currentSite.json", obj)
256+
257+
obj, _ := json.Marshal(site)
258+
cmdutil.WriteFile("currentSite.json", obj)
259+
260+
} else if sharedok {
261+
obj, _ := json.Marshal(sharedsite)
262+
cmdutil.WriteFile("currentSite.json", obj)
225263
}
226264
}
227265
return siteInfo,sharedsiteInfo
@@ -250,3 +288,58 @@ func UpdatePhoneLogin(feature string, status bool) (*FeatureSchema, error) {
250288
}
251289
return &resultResp, err
252290
}
291+
292+
293+
func GetPermissionsfromAPI() ( error) {
294+
295+
coreAppData := conf.AdminConsoleAPIDomain + "/auth/permissions?"
296+
data, err := request.Rest(http.MethodGet, coreAppData, nil, "")
297+
var permissionsResp PermissionResponse
298+
var permission Permission
299+
if err != nil {
300+
return err
301+
}
302+
err = json.Unmarshal(data, &permissionsResp)
303+
permission = permissionsResp.Permissions
304+
err = storePermissionData(permission)
305+
if err != nil {
306+
return err
307+
}
308+
return nil
309+
}
310+
311+
312+
func storePermissionData(data Permission) (error) {
313+
var permissionobj = cmdutil.PermissionCommands
314+
permission := make(map[string]bool, len(permissionobj))
315+
for key, val := range permissionobj {
316+
v := reflect.ValueOf(&data).Elem().FieldByName(val)
317+
if v.IsValid() {
318+
permission[key] = v.Bool()
319+
}
320+
}
321+
obj, err := json.Marshal(permission)
322+
if err != nil {
323+
return nil
324+
}
325+
cmdutil.WriteFile("permission.json", obj)
326+
return nil
327+
}
328+
329+
func GetPermission(str string) (bool, error) {
330+
data, err := cmdutil.ReadFile("permission.json")
331+
if err != nil {
332+
return false, err
333+
}
334+
permission := make(map[string]bool)
335+
err = json.Unmarshal(data, &permission)
336+
if err != nil {
337+
return false, err
338+
}
339+
if permission[str] == false {
340+
fmt.Println("You don't have access to proceed, request access from the site owner. If you've already been granted access, log out and log back in. If the issue persists, contact LoginRadius support at ")
341+
fmt.Println( conf.DashboardDomain + "/support/tickets")
342+
return false , nil
343+
}
344+
return true , nil
345+
}

api/deployment.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ type VerifySmtpConfigSchema struct {
131131
type VerifySmtpConfigError struct {
132132
Description string `json:"description"`
133133
Message string `json:"message"`
134-
135134
}
136135

137136
func GetSites() (*SitesReponse, error) {

api/platformConfiguration.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,19 @@ func UpdatePasswordlessLogin(body []byte) (*PasswordlessLogin, error) {
438438
}
439439
return &resultResp, err
440440
}
441+
442+
func UpdateSiteFeatures (data FeatureSchema) error {
443+
url := conf.AdminConsoleAPIDomain + "/platform-configuration/app-features?"
444+
body, _ := json.Marshal(data)
445+
resp, err := request.Rest(http.MethodPost, url, nil, string(body))
446+
if err != nil {
447+
return err
448+
}
449+
var resObj FeatureSchema
450+
err = json.Unmarshal(resp, &resObj)
451+
if err != nil {
452+
return err
453+
}
454+
return nil
455+
456+
}

api/securityConfiguration.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ type EmailResponse struct {
2020
RegistrationType string `json:"RegistrationType"`
2121
}
2222

23+
type IPResponse struct {
24+
AllowedIPs []string `json:"AllowedIPs"`
25+
DeniedIPs []string `json:"DeniedIPs"`
26+
}
27+
2328
type RegistrationRestrictionTypeSchema struct {
2429
SelectedRestrictionType string `json:"selectedRestrictionType"`
2530
}
@@ -109,4 +114,40 @@ func AddEmailWhitelistBlacklist(restrictionType RegistrationRestrictionTypeSchem
109114
}
110115
}
111116
return nil
112-
}
117+
}
118+
119+
func GetIPAccessRestrictionList() (*IPResponse, error) {
120+
url := conf.AdminConsoleAPIDomain + "/security-configuration/ip-config?"
121+
resp, err := request.Rest(http.MethodGet, url, nil, "")
122+
if err != nil {
123+
return nil, err
124+
}
125+
var resObj IPResponse
126+
err = json.Unmarshal(resp, &resObj)
127+
if err != nil {
128+
return nil, err
129+
}
130+
return &resObj, nil
131+
132+
}
133+
134+
135+
func AddIPAccessRestrictionList(disabled bool, data IPResponse) error {
136+
137+
if disabled {
138+
domainUrl := conf.AdminConsoleAPIDomain + "/security-configuration/ip-config/reset?"
139+
_, err := request.Rest(http.MethodPut, domainUrl, nil, "")
140+
if err != nil {
141+
return err
142+
}
143+
} else {
144+
typeUrl := conf.AdminConsoleAPIDomain + "/security-configuration/ip-config?"
145+
body, _ := json.Marshal(data)
146+
_, err := request.Rest(http.MethodPut, typeUrl, nil, string(body))
147+
if err != nil {
148+
return err
149+
}
150+
}
151+
152+
return nil
153+
}

0 commit comments

Comments
 (0)