Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk 2422 go fix code smells #303

Merged
merged 5 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import "github.com/getyoti/yoti-go-sdk/v3"
or add the following line to your go.mod file (check https://github.com/getyoti/yoti-go-sdk/releases for the latest version)
```
require github.com/getyoti/yoti-go-sdk/v3 v3.11.0
require github.com/getyoti/yoti-go-sdk/v3 v3.12.0
```

## Setup
Expand Down
2 changes: 1 addition & 1 deletion consts/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package consts

const (
SDKIdentifier = "Go"
SDKVersionIdentifier = "3.11.0"
SDKVersionIdentifier = "3.12.0"
)
2 changes: 1 addition & 1 deletion digitalidentity/requests/signed_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRequestShouldBuildForValid(t *testing.T) {
assert.Check(t, urlCheck)
assert.Check(t, signed.Header.Get("X-Yoti-Auth-Digest") != "")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK"), "Go")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.11.0")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.12.0")
}

func TestRequestShouldAddHeaders(t *testing.T) {
Expand Down
35 changes: 19 additions & 16 deletions digitalidentity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const identitySessionQrCodeCreation = "/v2/sessions/%s/qr-codes"
const identitySessionQrCodeRetrieval = "/v2/qr-codes/%s"
const identitySessionReceiptRetrieval = "/v2/receipts/%s"
const identitySessionReceiptKeyRetrieval = "/v2/wrapped-item-keys/%s"
const errorFailedToGetSignedRequest = "failed to get signed request: %v"
const errorFailedToExecuteRequest = "failed to execute request: %v"
const errorFailedToReadBody = "failed to read response body: %v"

// CreateShareSession creates session using the supplied session specification
func CreateShareSession(httpClient requests.HttpClient, shareSessionRequest *ShareSessionRequest, clientSdkId, apiUrl string, key *rsa.PrivateKey) (*ShareSession, error) {
Expand All @@ -40,20 +43,20 @@ func CreateShareSession(httpClient requests.HttpClient, shareSessionRequest *Sha
Params: map[string]string{"sdkID": clientSdkId},
}.Request()
if err != nil {
return nil, fmt.Errorf("failed to get signed request: %v", err)
return nil, fmt.Errorf(errorFailedToGetSignedRequest, err)
}

response, err := requests.Execute(httpClient, request)
if err != nil {
return nil, fmt.Errorf("failed to execute request: %v", err)
return nil, fmt.Errorf(errorFailedToExecuteRequest, err)
}

defer response.Body.Close()
shareSession := &ShareSession{}

responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
return nil, fmt.Errorf(errorFailedToReadBody, err)
}
err = json.Unmarshal(responseBytes, shareSession)
return shareSession, err
Expand All @@ -72,19 +75,19 @@ func GetShareSession(httpClient requests.HttpClient, sessionID string, clientSdk
Params: map[string]string{"sdkID": clientSdkId},
}.Request()
if err != nil {
return nil, fmt.Errorf("failed to get signed request: %v", err)
return nil, fmt.Errorf(errorFailedToGetSignedRequest, err)
}

response, err := requests.Execute(httpClient, request)

if err != nil {
return nil, fmt.Errorf("failed to execute request: %v", err)
return nil, fmt.Errorf(errorFailedToExecuteRequest, err)
}
defer response.Body.Close()
shareSession := &ShareSession{}
responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
return nil, fmt.Errorf(errorFailedToReadBody, err)
}
err = json.Unmarshal(responseBytes, shareSession)
return shareSession, err
Expand All @@ -104,19 +107,19 @@ func CreateShareQrCode(httpClient requests.HttpClient, sessionID string, clientS
Params: map[string]string{"sdkID": clientSdkId},
}.Request()
if err != nil {
return nil, fmt.Errorf("failed to get signed request: %v", err)
return nil, fmt.Errorf(errorFailedToGetSignedRequest, err)
}

response, err := requests.Execute(httpClient, request)
if err != nil {
return nil, fmt.Errorf("failed to execute request: %v", err)
return nil, fmt.Errorf(errorFailedToExecuteRequest, err)
}

defer response.Body.Close()
qrCode := &QrCode{}
responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %v", err)
return nil, fmt.Errorf(errorFailedToReadBody, err)
}
err = json.Unmarshal(responseBytes, qrCode)
return qrCode, err
Expand All @@ -134,18 +137,18 @@ func GetShareSessionQrCode(httpClient requests.HttpClient, qrCodeId string, clie
Headers: headers,
}.Request()
if err != nil {
return fetchedQrCode, fmt.Errorf("failed to get signed request: %v", err)
return fetchedQrCode, fmt.Errorf(errorFailedToGetSignedRequest, err)
}

response, err := requests.Execute(httpClient, request)
if err != nil {
return fetchedQrCode, fmt.Errorf("failed to execute request: %v", err)
return fetchedQrCode, fmt.Errorf(errorFailedToExecuteRequest, err)
}
defer response.Body.Close()

responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return fetchedQrCode, fmt.Errorf("failed to read response body: %v", err)
return fetchedQrCode, fmt.Errorf(errorFailedToReadBody, err)
}

err = json.Unmarshal(responseBytes, &fetchedQrCode)
Expand All @@ -167,18 +170,18 @@ func getReceipt(httpClient requests.HttpClient, receiptId string, clientSdkId, a
Headers: headers,
}.Request()
if err != nil {
return receipt, fmt.Errorf("failed to get signed request: %v", err)
return receipt, fmt.Errorf(errorFailedToGetSignedRequest, err)
}

response, err := requests.Execute(httpClient, request)
if err != nil {
return receipt, fmt.Errorf("failed to execute request: %v", err)
return receipt, fmt.Errorf(errorFailedToExecuteRequest, err)
}
defer response.Body.Close()

responseBytes, err := io.ReadAll(response.Body)
if err != nil {
return receipt, fmt.Errorf("failed to read response body: %v", err)
return receipt, fmt.Errorf(errorFailedToReadBody, err)
}

err = json.Unmarshal(responseBytes, &receipt)
Expand All @@ -198,7 +201,7 @@ func getReceiptItemKey(httpClient requests.HttpClient, receiptItemKeyId string,
Headers: headers,
}.Request()
if err != nil {
return receiptItemKey, fmt.Errorf("failed to get signed request: %v", err)
return receiptItemKey, fmt.Errorf(errorFailedToGetSignedRequest, err)
}

response, err := requests.Execute(httpClient, request)
Expand Down
7 changes: 0 additions & 7 deletions requests/signed_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func JSONHeaders() map[string][]string {
}
}

// AuthHeader is a header prototype including the App/SDK ID
func AuthHeader(clientSdkId string, key *rsa.PublicKey) map[string][]string {
return map[string][]string{
"X-Yoti-Auth-Id": {clientSdkId},
}
}

// AuthKeyHeader is a header prototype including an encoded RSA PublicKey
func AuthKeyHeader(key *rsa.PublicKey) map[string][]string {
return map[string][]string{
Expand Down
2 changes: 1 addition & 1 deletion requests/signed_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestRequestShouldBuildForValid(t *testing.T) {
assert.Check(t, urlCheck)
assert.Check(t, signed.Header.Get("X-Yoti-Auth-Digest") != "")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK"), "Go")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.11.0")
assert.Equal(t, signed.Header.Get("X-Yoti-SDK-Version"), "3.12.0")
}

func TestRequestShouldAddHeaders(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.organization = getyoti
sonar.projectKey = getyoti:go
sonar.projectName = Go SDK
sonar.projectVersion = 3.11.0
sonar.projectVersion = 3.12.0
sonar.exclusions = **/yotiprotoattr/*.go,**/yotiprotocom/*.go,**/yotiprotoshare/*.go,**/**_test.go,_examples/**/*
sonar.links.scm = https://github.com/getyoti/yoti-go-sdk
sonar.host.url = https://sonarcloud.io
Expand Down
Loading