Skip to content

Commit

Permalink
perf(idntranslator & ResponseTranslator class): deprecated API IDN Co…
Browse files Browse the repository at this point in the history
…nversion, integrated GOLang IDN library with tests, and ResponseTranslator tests
  • Loading branch information
AsifNawaz-cnic committed May 15, 2024
1 parent 74afae1 commit 67a2899
Show file tree
Hide file tree
Showing 16 changed files with 1,408 additions and 1,780 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Step 1: Use a temporary image to pull ellerbrock/bash-it
FROM ellerbrock/bash-it:latest AS bash_it

FROM mcr.microsoft.com/devcontainers/go:latest

RUN apt-get update && apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*

# Copy bash-it configurations from the temporary image
COPY --from=bash_it /root/.bash_it /home/vscode/.bash_it
RUN chown -R vscode:vscode /home/vscode/.bash_it
# Set the default shell to Bash
SHELL ["/bin/bash", "-c"]

# Start a simple loop to keep the container running
CMD ["sh", "-c", "while true; do sleep 3600; done"]
33 changes: 33 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "rtldev-middleware-go-sdk",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"settings": {
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"golang.go"
]
}
},
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/git:1": {}
},
"forwardPorts": [
8080
],
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE},target=/WSL_USER,type=bind,consistency=cached"
],
"postCreateCommand": "bash ./.devcontainer/post-create.sh",
"runArgs": ["--name", "rtldev-middleware-go-sdk"],
"remoteUser": "vscode"
}
6 changes: 6 additions & 0 deletions .devcontainer/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
~/.bash_it/install.sh --silent
bash-it update
rm -rf ~/.bash_history && ln -s /WSL_USER/.bash_history ~/.bash_history
go mod tidy
sed -i "s/export BASH_IT_THEME='bobby'/export BASH_IT_THEME='powerline'/" ~/.bashrc
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ coverage.html
node_modules

# go binary
go-sdk
rtldev-middleware-go-sdk
8 changes: 1 addition & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ linters:
- goconst
- goimports
- gocritic
- govet
- revive
- shadow # Added shadow linter
linters-settings:
errcheck:
# report about assignment of errors to blank identifier
# default is false: such cases aren't reported by default.
check-blank: true
govet:
# report about shadowed variables
shadow: true
gocyclo:
# minimal code complexity to report, 30 by default
min-complexity: 15
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
28 changes: 8 additions & 20 deletions apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"strings"
"time"

IDN "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/idntranslator"
LG "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/logger"
R "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/response"
RTM "github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3/responsetemplatemanager"
Expand All @@ -30,10 +31,10 @@ import (
const ISPAPI_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
const ISPAPI_CONNECTION_URL_LIVE = "hapi.ispapi.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
const ISPAPI_CONNECTION_URL_OTE = "hapi-ote.ispapi.net/api/call.cgi" //nolint

var rtm = RTM.GetInstance()

Expand All @@ -49,7 +50,7 @@ var rtm = RTM.GetInstance()
// A sessionless communication makes sense in case you do not need
// to care about the above and you have just to request some commands.
//
// Possible commands can be found at https://github.com/hexonet/hexonet-api-documentation/tree/master/API
// Possible commands can be found at hgithub.com/hexonet/hexonet-api-documentation/tree/master/API
type APIClient struct {
socketTimeout time.Duration
socketURL string
Expand Down Expand Up @@ -522,9 +523,6 @@ func (cl *APIClient) flattenCommand(cmd map[string]interface{}) map[string]strin

// autoIDNConvert method to translate all whitelisted parameter values to punycode, if necessary
func (cl *APIClient) autoIDNConvert(cmd map[string]string) map[string]string {
newcmd := map[string]string{
"COMMAND": "ConvertIDN",
}
// don't convert for convertidn command to avoid endless loop
pattern := regexp.MustCompile(`(?i)^CONVERTIDN$`)
mm := pattern.MatchString(cmd["COMMAND"])
Expand Down Expand Up @@ -553,25 +551,15 @@ func (cl *APIClient) autoIDNConvert(cmd map[string]string) map[string]string {
if mm {
toconvert = append(toconvert, val)
idxs = append(idxs, key)
} else {
newcmd[key] = val
}
}
if len(toconvert) == 0 {
return cmd
}
r := cl.Request(map[string]interface{}{
"COMMAND": "ConvertIDN",
"DOMAIN": toconvert,
})
if !r.IsSuccess() {
return cmd
}
col := r.GetColumn("ACE")
if col != nil {
for idx, pc := range col.GetData() {
cmd[idxs[idx]] = pc
}
r := IDN.Convert(toconvert)

for idx, pc := range r {
cmd[idxs[idx]] = pc.PUNYCODE
}
return cmd
}
7 changes: 4 additions & 3 deletions apiclient/apiclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ func TestAutoIDNConvertCommand(t *testing.T) {
cl.UseOTESystem()
r := cl.Request(map[string]interface{}{
"COMMAND": "CheckDomains",
"DOMAiN": []string{"example.com", "dömäin.example", "example.net"},
"DOMAIN": []string{"example.com", "dömäin.example", "example.net"},
})
if !r.IsSuccess() || r.GetCode() != 200 || r.GetDescription() != "Command completed successfully" {
t.Error("TestRequestFlattenCommand: Expected response to succeed." + strconv.Itoa(r.GetCode()) + r.GetDescription())
}
cmd := r.GetCommand()

val1, exists1 := cmd["DOMAIN0"]
val2, exists2 := cmd["DOMAIN1"]
val3, exists3 := cmd["DOMAIN2"]
Expand Down Expand Up @@ -315,9 +316,9 @@ func TestSetProxy(t *testing.T) {
}

func TestSetReferer(t *testing.T) {
cl.SetReferer("https://www.hexonet.net/")
cl.SetReferer("hwww.hexonet.net/")
val, err := cl.GetReferer()
if err != nil || val != "https://www.hexonet.net/" {
if err != nil || val != "hwww.hexonet.net/" {
t.Error("TestSetReferer: referer not matching expected value")
}
cl.SetReferer("")
Expand Down
14 changes: 13 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
module github.com/centralnicgroup-opensource/rtldev-middleware-go-sdk/v3

go 1.20
go 1.22.3

require (
github.com/stretchr/testify v1.9.0
golang.org/x/net v0.25.0
golang.org/x/text v0.15.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 67a2899

Please sign in to comment.