Skip to content

Commit

Permalink
feat(centralnic reseller go-sdk): introducing CNR Go-SDK API Connector
Browse files Browse the repository at this point in the history
BREAKING CHANGE: We have deprecated hexonet go sdk and introduced centralnic reseller go sdk due to
merger of Hexonet to CNR
  • Loading branch information
AsifNawaz-cnic committed Aug 23, 2024
1 parent f6b96a0 commit c2ba588
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 260 deletions.
60 changes: 19 additions & 41 deletions apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import (
SC "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/socketconfig"
)

// ISPAPI_CONNECTION_URL_PROXY represents the url used for the high performance connection setup
const ISPAPI_CONNECTION_URL_PROXY = "http://127.0.0.1/api/call.cgi" //nolint
// CNR_CONNECTION_URL_PROXY represents the url used for the high performance connection setup
const CNR_CONNECTION_URL_PROXY = "http://127.0.0.1/api/call.cgi" //nolint

// ISPAPI_CONNECTION_URL_LIVE represents the url used for the default connection setup
const ISPAPI_CONNECTION_URL_LIVE = "https://api.ispapi.net/api/call.cgi" //nolint
// CNR_CONNECTION_URL_LIVE represents the url used for the default connection setup
const CNR_CONNECTION_URL_LIVE = "https://api.rrpproxy.net/api/call.cgi" //nolint

// ISPAPI_CONNECTION_URL_OTE represents the url used for the OT&E (demo system) connection setup
const ISPAPI_CONNECTION_URL_OTE = "https://api-ote.ispapi.net/api/call.cgi" //nolint
// CNR_CONNECTION_URL_OTE represents the url used for the OT&E (demo system) connection setup
const CNR_CONNECTION_URL_OTE = "https://api-ote.rrpproxy.net/api/call.cgi" //nolint

var rtm = RTM.GetInstance()

Expand Down Expand Up @@ -66,7 +66,7 @@ func NewAPIClient() *APIClient {
cl := &APIClient{
debugMode: false,
socketTimeout: 300 * time.Second,
socketURL: ISPAPI_CONNECTION_URL_LIVE,
socketURL: CNR_CONNECTION_URL_LIVE,
socketConfig: SC.NewSocketConfig(),
curlopts: map[string]string{},
ua: "",
Expand Down Expand Up @@ -139,6 +139,12 @@ func (cl *APIClient) DisableDebugMode() *APIClient {
return cl
}

// UseHighPerformanceConnectionSetup to activate high performance conneciton setup
func (cl *APIClient) UseHighPerformanceConnectionSetup() *APIClient {
cl.SetURL(CNR_CONNECTION_URL_PROXY)
return cl
}

// GetPOSTData method to Serialize given command for POST request
// including connection configuration data
func (cl *APIClient) GetPOSTData(cmd map[string]string, secured ...bool) string {
Expand Down Expand Up @@ -219,7 +225,6 @@ func (cl *APIClient) GetVersion() string {
// Please save/update that map into user session
func (cl *APIClient) SaveSession(sessionobj map[string]interface{}) *APIClient {
sessionobj["socketcfg"] = map[string]string{
"entity": cl.socketConfig.GetSystemEntity(),
"session": cl.socketConfig.GetSession(),
}
return cl
Expand All @@ -229,7 +234,6 @@ func (cl *APIClient) SaveSession(sessionobj map[string]interface{}) *APIClient {
// to rebuild and reuse connection settings
func (cl *APIClient) ReuseSession(sessionobj map[string]interface{}) *APIClient {
cfg := sessionobj["socketcfg"].(map[string]string)
cl.socketConfig.SetSystemEntity(cfg["entity"])
cl.SetSession(cfg["session"])
return cl
}
Expand All @@ -252,12 +256,6 @@ func (cl *APIClient) SetSession(value string) *APIClient {
return cl
}

// SetRemoteIPAddress method to set an Remote IP Address to be used for API communication
func (cl *APIClient) SetRemoteIPAddress(value string) *APIClient {
cl.socketConfig.SetRemoteAddress(value)
return cl
}

// SetCredentials method to set Credentials to be used for API communication
func (cl *APIClient) SetCredentials(uid string, pw string) *APIClient {
cl.socketConfig.SetLogin(uid)
Expand All @@ -268,7 +266,7 @@ func (cl *APIClient) SetCredentials(uid string, pw string) *APIClient {
// SetRoleCredentials method to set Role User Credentials to be used for API communication
func (cl *APIClient) SetRoleCredentials(uid string, role string, pw string) *APIClient {
if len(role) > 0 {
return cl.SetCredentials(uid+"!"+role, pw)
return cl.SetCredentials(uid+":"+role, pw)
}
return cl.SetCredentials(uid, pw)
}
Expand All @@ -283,7 +281,7 @@ func (cl *APIClient) Login(params ...string) *R.Response {
cl.SetOTP(otp)
rr := cl.Request(map[string]interface{}{"COMMAND": "StartSession"})
if rr.IsSuccess() {
col := rr.GetColumn("SESSION")
col := rr.GetColumn("SESSIONID")
if col != nil {
cl.SetSession(col.GetData()[0])
} else {
Expand Down Expand Up @@ -314,7 +312,7 @@ func (cl *APIClient) LoginExtended(params ...interface{}) *R.Response {
}
rr := cl.Request(cmd)
if rr.IsSuccess() {
col := rr.GetColumn("SESSION")
col := rr.GetColumn("SESSIONID")
if col != nil {
cl.SetSession(col.GetData()[0])
} else {
Expand Down Expand Up @@ -460,42 +458,22 @@ func (cl *APIClient) RequestAllResponsePages(cmd map[string]string) []R.Response
return responses
}

// SetUserView method to set a data view to a given subuser
func (cl *APIClient) SetUserView(uid string) *APIClient {
cl.socketConfig.SetUser(uid)
return cl
}

// ResetUserView method to reset data view back from subuser to user
func (cl *APIClient) ResetUserView() *APIClient {
cl.socketConfig.SetUser("")
return cl
}

// UseHighPerformanceConnectionSetup to activate high performance conneciton setup
func (cl *APIClient) UseHighPerformanceConnectionSetup() *APIClient {
cl.SetURL(ISPAPI_CONNECTION_URL_PROXY)
return cl
}

// UseDefaultConnectionSetup to activate default conneciton setup (the default anyways)
func (cl *APIClient) UseDefaultConnectionSetup() *APIClient {
cl.SetURL(ISPAPI_CONNECTION_URL_LIVE)
cl.SetURL(CNR_CONNECTION_URL_LIVE)
return cl
}

// UseOTESystem method to set OT&E System for API communication
func (cl *APIClient) UseOTESystem() *APIClient {
cl.SetURL(ISPAPI_CONNECTION_URL_OTE)
cl.socketConfig.SetSystemEntity("1234")
cl.SetURL(CNR_CONNECTION_URL_OTE)
return cl
}

// UseLIVESystem method to set LIVE System for API communication
// Usage of LIVE System is active by default.
func (cl *APIClient) UseLIVESystem() *APIClient {
cl.SetURL(ISPAPI_CONNECTION_URL_LIVE)
cl.socketConfig.SetSystemEntity("54cd")
cl.SetURL(CNR_CONNECTION_URL_LIVE)
return cl
}

Expand Down
Loading

0 comments on commit c2ba588

Please sign in to comment.