Skip to content

Commit 21c445c

Browse files
feat(centralnic-reseller-go-sdk): introducing CentralNic Reseller Go SDK API Connector
BREAKING CHANGE: We have deprecated the Hexonet Go SDK and introduced the CentralNic Reseller Go SDK.
1 parent f6b96a0 commit 21c445c

File tree

17 files changed

+471
-431
lines changed

17 files changed

+471
-431
lines changed

apiclient/apiclient.go

Lines changed: 150 additions & 103 deletions
Large diffs are not rendered by default.

apiclient/apiclient_test.go

Lines changed: 119 additions & 167 deletions
Large diffs are not rendered by default.

column/column.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ func (c *Column) GetKey() string {
3232

3333
// GetData method to return the column data
3434
func (c *Column) GetData() []string {
35+
if c == nil {
36+
return nil
37+
}
3538
return c.data
3639
}
3740

@@ -40,7 +43,7 @@ func (c *Column) GetDataByIndex(idx int) (string, error) {
4043
if c.hasDataIndex(idx) {
4144
return c.data[idx], nil
4245
}
43-
return "", errors.New("Index not found")
46+
return "", errors.New("index not found")
4447
}
4548

4649
// hasDataIndex method to check if the given data index exists

customlogger/customlogger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ package customlogger
99
import (
1010
"fmt"
1111

12-
L "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/logger"
13-
R "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/response"
12+
L "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/logger"
13+
R "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/response"
1414
)
1515

1616
// Logger is a struct representing logger for API communication.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4
1+
module github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5
22

33
go 1.22.1 // using this version to make it compatible with dnscontrol
44

idntranslator/idntranslator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package idntranslator_test
33
import (
44
"testing"
55

6-
"github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/idntranslator"
6+
"github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/idntranslator"
77

88
"github.com/stretchr/testify/assert"
99
)

logger/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package logger
99
import (
1010
"fmt"
1111

12-
R "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/response"
12+
R "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/response"
1313
)
1414

1515
// ilogger reflect basic interface for loggers

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "go-sdk",
3-
"description": "GO/GOLANG SDK for the insanely fast HEXONET API",
3+
"description": "GO/GOLANG SDK for the insanely fast CentralNic Reseller (fka RRPProxy) API",
44
"version": "0.0.0-development",
55
"private": true,
66
"author": {
77
"name": "Kai Schwarz",
8-
"email": "[email protected]"
8+
"email": "[email protected]"
99
},
1010
"license": "MIT",
1111
"engines": {
@@ -17,16 +17,20 @@
1717
"maintainers": [
1818
{
1919
"name": "Kai Schwarz",
20-
"email": "[email protected]"
20+
"email": "[email protected]"
21+
},
22+
{
23+
"name": "Asif Nawaz",
24+
"email": "[email protected]"
2125
}
2226
],
2327
"keywords": [
24-
"hexonet",
28+
"cnr",
2529
"domain",
2630
"api",
2731
"connector",
28-
"isp",
29-
"ispapi",
32+
"cnic",
33+
"centralnic reseller",
3034
"ssl",
3135
"cert",
3236
"dns",

record/record.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ func (c *Record) GetData() map[string]string {
2828

2929
// GetDataByKey method to return the column data at the provided index
3030
func (c *Record) GetDataByKey(key string) (string, error) {
31+
if c == nil {
32+
return "", errors.New("record is nil")
33+
}
3134
if c.hasData(key) {
3235
return c.data[key], nil
3336
}

response/response.go

Lines changed: 81 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
"strconv"
1414
"strings"
1515

16-
"github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/column"
17-
"github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/record"
18-
rp "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/responseparser"
19-
rt "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v4/responsetranslator"
16+
"github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/column"
17+
"github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/record"
18+
rp "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/responseparser"
19+
rt "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v5/responsetranslator"
2020
)
2121

2222
// Response is a struct used to cover basic functionality to work with
@@ -31,7 +31,17 @@ type Response struct {
3131
records []record.Record
3232
}
3333

34-
// NewResponse represents the constructor for struct Response.
34+
const defaultCode = 421
35+
36+
// NewResponse creates a new Response object.
37+
// It takes a raw string, a command map, and optional placeholder maps as parameters.
38+
// The function replaces the "PASSWORD" value in the command map with "***" if it exists.
39+
// It then translates the raw string using the command and placeholder maps.
40+
// The function initializes a new Response object with the translated raw string, a hash value,
41+
// the command map, empty column keys and columns, a record index of 0, and an empty records slice.
42+
// If the hash value contains a "PROPERTY" key, the function adds columns and records to the Response object
43+
// based on the values in the "PROPERTY" map.
44+
// The function returns the newly created Response object.
3545
func NewResponse(raw string, cmd map[string]string, phs ...map[string]string) *Response {
3646
ph := map[string]string{}
3747
if len(phs) > 0 {
@@ -88,20 +98,53 @@ func NewResponse(raw string, cmd map[string]string, phs ...map[string]string) *R
8898
return r
8999
}
90100

91-
// GetCode method to return the API response code
101+
// GetCode returns the code associated with the response.
102+
// If the response does not have a code or if the code is not a valid integer,
103+
// it returns the default code.
104+
//
105+
// The code is retrieved from the response's hash, which is a map[string]interface{}.
106+
// The code value is expected to be stored under the key "CODE" as a string.
107+
// If the code value is not found or is not a string, the default code is returned.
108+
//
109+
// If an error occurs while converting the code string to an integer,
110+
// the default code is returned and the error is logged or handled appropriately.
111+
//
112+
// Returns:
113+
// - int: The code associated with the response.
92114
func (r *Response) GetCode() int {
93115
h := r.GetHash()
94-
c, err := strconv.Atoi(h["CODE"].(string))
95-
if err == nil {
96-
return c
116+
if h == nil {
117+
return defaultCode
118+
}
119+
120+
codeStr, ok := h["CODE"].(string)
121+
if !ok {
122+
// Log or handle the error appropriately
123+
return defaultCode
124+
}
125+
126+
c, err := strconv.Atoi(codeStr)
127+
if err != nil {
128+
// Log or handle the error appropriately
129+
return defaultCode
97130
}
98-
return 421
131+
return c
99132
}
100133

101134
// GetDescription method to return the API response description
102135
func (r *Response) GetDescription() string {
103136
h := r.GetHash()
104-
return h["DESCRIPTION"].(string)
137+
if h == nil {
138+
return ""
139+
}
140+
141+
// Assuming there is a "DESCRIPTION" key in the hash
142+
desc, ok := h["DESCRIPTION"].(string)
143+
if !ok {
144+
// Log or handle the error appropriately
145+
return ""
146+
}
147+
return desc
105148
}
106149

107150
// GetPlain method to return raw API response
@@ -158,12 +201,23 @@ func (r *Response) IsTmpError() bool {
158201

159202
// IsPending method to check if current operation is returned as pending
160203
func (r *Response) IsPending() bool {
161-
h := r.GetHash()
162-
if val, ok := h["PENDING"]; ok {
163-
if val.(string) == "1" {
164-
return true
204+
cmd := r.GetCommand()
205+
206+
// Check if the COMMAND is AddDomain (case-insensitive)
207+
if command, ok := cmd["COMMAND"]; !ok || !strings.EqualFold(command, "AddDomain") {
208+
return false
209+
}
210+
211+
// Retrieve the STATUS column and check if its data equals REQUESTED (case-insensitive)
212+
status := r.GetColumn("STATUS")
213+
if status != nil {
214+
statusData, err := status.GetDataByIndex(0)
215+
if err != nil {
216+
return false
165217
}
218+
return strings.EqualFold(statusData, "REQUESTED")
166219
}
220+
167221
return false
168222
}
169223

@@ -199,7 +253,7 @@ func (r *Response) GetColumnIndex(key string, index int) (string, error) {
199253
return d, nil
200254
}
201255
}
202-
return "", errors.New("Column Data Index does not exist")
256+
return "", errors.New("column Data Index does not exist")
203257
}
204258

205259
// GetColumnKeys method to get the list of column names
@@ -242,7 +296,7 @@ func (r *Response) GetCurrentPageNumber() (int, error) {
242296
if ferr == nil && limit > 0 {
243297
return int(math.Floor(float64(first)/float64(limit))) + 1, nil
244298
}
245-
return 0, errors.New("Could not find current page number")
299+
return 0, errors.New("could not find current page number")
246300
}
247301

248302
// GetCurrentRecord method to get record of current record index
@@ -263,14 +317,14 @@ func (r *Response) GetFirstRecordIndex() (int, error) {
263317
if err2 == nil {
264318
return idx, nil
265319
}
266-
return 0, errors.New("Could not find first record index")
320+
return 0, errors.New("could not find first record index")
267321
}
268322
}
269323
tlen := len(r.records)
270324
if tlen > 1 {
271325
return 0, nil
272326
}
273-
return 0, errors.New("Could not find first record index")
327+
return 0, errors.New("could not find first record index")
274328
}
275329

276330
// GetLastRecordIndex method to get last record index of the current list query
@@ -283,14 +337,14 @@ func (r *Response) GetLastRecordIndex() (int, error) {
283337
if err2 == nil {
284338
return idx, nil
285339
}
286-
return 0, errors.New("Could not find last record index")
340+
return 0, errors.New("could not find last record index")
287341
}
288342
}
289343
tlen := r.GetRecordsCount()
290344
if tlen > 0 {
291345
return (tlen - 1), nil
292346
}
293-
return 0, errors.New("Could not find last record index")
347+
return 0, errors.New("could not find last record index")
294348
}
295349

296350
// GetListHash method to get Response as List Hash including useful meta data for tables
@@ -322,7 +376,7 @@ func (r *Response) GetNextRecord() *record.Record {
322376
func (r *Response) GetNextPageNumber() (int, error) {
323377
cp, err := r.GetCurrentPageNumber()
324378
if err != nil {
325-
return 0, errors.New("Could not find next page number")
379+
return 0, errors.New("could not find next page number")
326380
}
327381
page := cp + 1
328382
pages := r.GetNumberOfPages()
@@ -385,7 +439,7 @@ func (r *Response) GetPreviousPageNumber() (int, error) {
385439
}
386440
pp := cp - 1
387441
if pp < 1 {
388-
return 0, errors.New("Could not find previous page number")
442+
return 0, errors.New("could not find previous page number")
389443
}
390444
return pp, nil
391445
}
@@ -472,14 +526,15 @@ func (r *Response) RewindRecordList() *Response {
472526
return r
473527
}
474528

475-
// hasColumn method to check if the given column exists in column list
529+
// hasColumn method to check if the given column exists in column list (case-insensitive)
476530
func (r *Response) hasColumn(key string) (int, bool) {
531+
lowerKey := strings.ToLower(key)
477532
for i, k := range r.columnkeys {
478-
if k == key {
533+
if strings.ToLower(k) == lowerKey {
479534
return i, true
480535
}
481536
}
482-
return 0, false
537+
return -1, false
483538
}
484539

485540
// hasCurrentRecord method to check if the record on current record index exists

0 commit comments

Comments
 (0)