Skip to content

Commit

Permalink
Code refactor and Test cases (#12)
Browse files Browse the repository at this point in the history
* Path fixes for publishing to go package

* Remove deprecated golang methods. Other refactors. Updated Readme

* Resolved conflicts. Removed unwanted console logs

* Code refactor. Test cases. Removed SqlViews

* Read from .env or exported variables

* Fixes to env read

* Trigger CICD workflow

* Final test fixes

* Removed prefix env var
  • Loading branch information
chilaraiSxt authored May 7, 2024
1 parent d2d60be commit 96c505a
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 540 deletions.
6 changes: 5 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ BASEURL_DISCOVERY="https://<base_url>/v2" # Space and Time Discovery API Endpoi
USERID="" # UserID required for authentication and authorization
JOINCODE="" # Space and Time Join Code which can be got from the SxT release team
SCHEME="ed25519" # The key scheme or algorithm required for key generation
PREFIX="" # Optional Prefix Parameter for signature generation

# TEST
TEST_USER=
TEST_USER_PRIVKEY=
TEST_USER_PUBKEY=
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# go-sxt-sdk (v.0.0.7)
# go-sxt-sdk (v.0.0.8)

Golang SDK for Space and Time Gateway (go version >= 1.18)

Expand Down Expand Up @@ -87,7 +87,7 @@ The generated `AccessToken` is valid for 25 minutes and the `refreshToken` for 3
```go
// New Authentication.
// Generates new accessToken, refreshToken, privateKey, and publicKey
func authenticate()(accessToken, refreshToken string, privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey){
func Authenticate()(accessToken, refreshToken string, privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey){

// Read userId, joinCode from .env file
userId, _ := helpers.ReadUserId()
Expand Down
86 changes: 38 additions & 48 deletions helpers/readenvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,81 @@ package helpers
import (
"log"
"os"
"path/filepath"

"github.com/joho/godotenv"
)

// Read User Id from Environment
func ReadUserId() (value string, ok bool){
err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}

value, ok = os.LookupEnv("USERID")

if !ok {
log.Fatal("USERID not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["USERID"]

if value == ""{
log.Fatal("USERID not set in environment")
}
}
return value, ok

return value, true
}

// Read Join Code from Environment
func ReadJoinCode() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("JOINCODE")

if !ok {
log.Fatal("JOINCODE not set in environment")
}
envFile, _ := godotenv.Read(".env")
value = envFile["JOINCODE"]

return value, ok
if value == ""{
log.Fatal("JOINCODE not set in environment")
}
}

return value, true
}

// Read API End Point Discovery from Environment
func ReadEndPointDiscovery() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("BASEURL_DISCOVERY")

if !ok {
log.Fatal("Discovery BASEURL not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["BASEURL_DISCOVERY"]

if value == ""{
log.Fatal("BASEURL_DISCOVERY not set in environment")
}
}
return value, ok
return value, true
}

// Read API End Point Others in General from Environment
func ReadEndPointGeneral() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("BASEURL_GENERAL")

if !ok {
log.Fatal("General BASEURL not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["BASEURL_GENERAL"]

if value == ""{
log.Fatal("BASEURL_GENERAL not set in environment")
}
}
return value, ok

return value, true
}

// Read Scheme from Environment
func ReadScheme() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("SCHEME")

if !ok {
log.Fatal("SCHEME not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["SCHEME"]

if value == ""{
log.Fatal("SCHEME not set in environment")
}
}
return value, ok
return value, true
}
Loading

0 comments on commit 96c505a

Please sign in to comment.