Skip to content

Commit c9a5c29

Browse files
More go and python fixes (#483)
1 parent a025c2a commit c9a5c29

File tree

10 files changed

+49
-57
lines changed

10 files changed

+49
-57
lines changed

.github/workflows/build-python.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ jobs:
5656
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
5757
LD_LIBRARY_PATH: "${{ github.workspace }}/libs"
5858
TEST_SERVER_ENDPOINT: ${{ secrets.TEST_SERVER_ENDPOINT }}
59-
TEST_SERVER_PORT: ${{ secrets.TEST_SERVER_PORT }}
60-
TEST_SERVER_USE_TLS: ${{ secrets.TEST_SERVER_USE_TLS }}
59+
# TEST_SERVER_PORT: ${{ secrets.TEST_SERVER_PORT }}
60+
# TEST_SERVER_USE_TLS: ${{ secrets.TEST_SERVER_USE_TLS }}
6161
- name: Upload Unit Test Results - Python
6262
if: always()
6363
uses: actions/upload-artifact@v2

go/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/trinsic-id/sdk/go
33
go 1.16
44

55
require (
6+
github.com/google/uuid v1.3.0 // indirect
67
github.com/stretchr/testify v1.7.0
78
github.com/trinsic-id/okapi/go v1.4.0
89
google.golang.org/grpc v1.41.0

go/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
5454
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
5555
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
5656
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
57+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
58+
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5759
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
5860
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
5961
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=

go/services/account_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (a *accountBase) SignIn(userContext context.Context, request *sdk.SignInReq
5353
if request == nil {
5454
request = &sdk.SignInRequest{}
5555
}
56+
if request.Details == nil {
57+
request.Details = &sdk.AccountDetails{}
58+
}
5659

5760
if len(request.EcosystemId) == 0 {
5861
request.EcosystemId = a.GetServiceOptions().DefaultEcosystem

go/services/service_base.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,23 @@ import (
1717
// NewServiceBase returns a base service which is the foundation
1818
// for all the other services
1919
func NewServiceBase(options *Options) (Service, error) {
20-
if options.Channel == nil {
21-
conn, err := NewServiceConnection(options.ServiceOptions)
22-
if err != nil {
23-
return nil, err
24-
}
25-
26-
options.Channel = conn
20+
conn, err := NewServiceConnection(options.ServiceOptions)
21+
if err != nil {
22+
return nil, err
2723
}
2824

2925
return &serviceBase{
3026
options: options,
27+
channel: conn,
3128
securityProvider: &OberonSecurityProvider{},
3229
}, nil
3330
}
3431

3532
// Service defines functionality common to all services
3633
type Service interface {
37-
// GetMetadatContext returns a context with the required grpc metadata embedded in it
34+
// GetMetadataContext returns a context with the required grpc metadata embedded in it
3835
GetMetadataContext(userContext context.Context, message proto.Message) (context.Context, error)
39-
// BuildMetdata builds the required grpc metadata
36+
// BuildMetadata builds the required grpc metadata
4037
BuildMetadata(message proto.Message) (metadata.MD, error)
4138
// SetToken assigns the given auth token to the service. This token will be used for
4239
// make all api calls
@@ -54,11 +51,12 @@ type Service interface {
5451

5552
type serviceBase struct {
5653
options *Options
54+
channel *grpc.ClientConn
5755
securityProvider SecurityProvider
5856
}
5957

6058
func (s *serviceBase) GetChannel() *grpc.ClientConn {
61-
return s.options.Channel
59+
return s.channel
6260
}
6361

6462
func (s *serviceBase) SetToken(authtoken string) {

go/services/service_base_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func TestServiceBase(t *testing.T) {
4949
ServerPort: 1234,
5050
DefaultEcosystem: "test"},
5151
),
52-
WithChannel(nconn),
5352
)
5453

5554
if !assert.Nil(err) {
@@ -59,7 +58,7 @@ func TestServiceBase(t *testing.T) {
5958
base, err = NewServiceBase(opts)
6059
assert.Nil(err)
6160
assert.Equal(opts.ServiceOptions, base.GetServiceOptions())
62-
assert.Equal("192.168.1.1:4321", base.GetChannel().Target(), "new grpc connection should be set")
61+
assert.Equal("127.0.0.1:1234", base.GetChannel().Target(), "new grpc connection should be set")
6362

6463
// we should have an empty auth profile
6564
assert.Empty(base.GetProfile(), "auth Profile should be empty")

go/services/services.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ import (
66
"strings"
77

88
sdk "github.com/trinsic-id/sdk/go/proto"
9-
"google.golang.org/grpc"
109
)
1110

1211
//Options for configuring the sdk
1312
type Options struct {
1413
ServiceOptions *sdk.ServiceOptions
15-
Channel *grpc.ClientConn
1614
}
1715

1816
// NewServiceOptions returns a service options configuration with the provided options set
@@ -119,20 +117,18 @@ func WithTestEnv() Option {
119117
s.ServiceOptions.ServerPort = int32(port)
120118

121119
useTLS := os.Getenv("TEST_SERVER_USE_TLS")
122-
if len(useTLS) != 0 && strings.Compare(strings.ToLower(useTLS), "false") != 0 {
123-
s.ServiceOptions.ServerUseTls = true
124-
} else {
120+
if len(useTLS) != 0 && strings.Compare(strings.ToLower(useTLS), "false") == 0 {
125121
s.ServiceOptions.ServerUseTls = false
122+
} else {
123+
s.ServiceOptions.ServerUseTls = true
126124
}
127125

128-
return nil
129-
}
130-
}
126+
defaultEcosystem := os.Getenv("TEST_SERVER_ECOSYSTEM")
127+
if len(defaultEcosystem) > 0 {
128+
} else {
129+
s.ServiceOptions.DefaultEcosystem = "default"
130+
}
131131

132-
// WithChannel will use the provided grpc channel instead of creating a default
133-
func WithChannel(conn *grpc.ClientConn) Option {
134-
return func(s *Options) error {
135-
s.Channel = conn
136132
return nil
137133
}
138134
}

go/services/services_test.go

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"runtime"
1010
"testing"
1111

12+
"github.com/google/uuid"
1213
"github.com/stretchr/testify/assert"
1314
sdk "github.com/trinsic-id/sdk/go/proto"
14-
"google.golang.org/grpc"
1515
)
1616

1717
// pathData() {
@@ -63,11 +63,6 @@ func TestServiceOptions(t *testing.T) {
6363
func TestVaccineCredentialsDemo(t *testing.T) {
6464
assert2 := assert.New(t)
6565

66-
err := createDefaultEcosystem()
67-
if !assert2.Nil(err) {
68-
return
69-
}
70-
7166
// Open in background
7267
opts, err := NewServiceOptions(WithTestEnv())
7368
if !assert2.Nil(err) {
@@ -79,8 +74,6 @@ func TestVaccineCredentialsDemo(t *testing.T) {
7974
return
8075
}
8176

82-
opts.Channel = accountService.GetChannel()
83-
8477
// if !accountService.GetChannel().WaitForStateChange(context.Background(), connectivity.Ready) {
8578
// t.Fail()
8679
// }
@@ -180,12 +173,12 @@ func TestVaccineCredentialsDemo(t *testing.T) {
180173
}
181174

182175
func TestTrustRegistryDemo(t *testing.T) {
183-
assert2, channel, authtoken, err := createAccountAndSignIn(t)
176+
assert2, authtoken, err := createAccountAndSignIn(t)
184177
if !assert2.Nil(err) {
185178
return
186179
}
187180

188-
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel))
181+
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken))
189182
if !assert2.Nil(err) {
190183
return
191184
}
@@ -242,26 +235,26 @@ func TestTrustRegistryDemo(t *testing.T) {
242235
assert2.NotEmpty(ecosystemList)
243236
}
244237

245-
func createAccountAndSignIn(t *testing.T) (*assert.Assertions, *grpc.ClientConn, string, error) {
238+
func createAccountAndSignIn(t *testing.T) (*assert.Assertions, string, error) {
246239
assert2 := assert.New(t)
247240
opts, err := NewServiceOptions(WithTestEnv())
248241
if !assert2.Nil(err) {
249-
return assert2, nil, "", err
242+
return assert2, "", err
250243
}
251244
// Open in background
252245
accountService, err := NewAccountService(opts)
253246
if !assert2.Nil(err) {
254-
return assert2, nil, "", err
247+
return assert2, "", err
255248
}
256249
authtoken, _, err := accountService.SignIn(context.Background(), &sdk.SignInRequest{})
257250
if !assert2.Nil(err) {
258251
fmt.Println(err)
259-
return assert2, nil, "", err
252+
return assert2, "", err
260253
}
261-
return assert2, accountService.GetChannel(), authtoken, nil
254+
return assert2, authtoken, nil
262255
}
263256

264-
func createDefaultEcosystem() error {
257+
func createRandomEcosystem() error {
265258
opts, err := NewServiceOptions(WithTestEnv())
266259
if err != nil {
267260
return err
@@ -272,17 +265,17 @@ func createDefaultEcosystem() error {
272265
return err
273266
}
274267

275-
_, err = ps.CreateEcosystem(context.Background(), &sdk.CreateEcosystemRequest{Name: "default"})
268+
_, err = ps.CreateEcosystem(context.Background(), &sdk.CreateEcosystemRequest{Name: "test-sdk-" + uuid.New().String()})
276269

277270
return err
278271
}
279272
func TestEcosystemDemo(t *testing.T) {
280-
assert2, channel, authtoken, err := createAccountAndSignIn(t)
273+
assert2, authtoken, err := createAccountAndSignIn(t)
281274
if !assert2.Nil(err) {
282275
return
283276
}
284277

285-
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel))
278+
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken))
286279
if !assert2.Nil(err) {
287280
return
288281
}
@@ -293,7 +286,7 @@ func TestEcosystemDemo(t *testing.T) {
293286
}
294287

295288
actualCreate, err := service.CreateEcosystem(context.Background(), &sdk.CreateEcosystemRequest{
296-
Name: "Test-Ecosystem",
289+
Name: "test-sdk-" + uuid.New().String(),
297290
Description: "My ecosystem",
298291
Uri: "https://example.com",
299292
})
@@ -314,12 +307,12 @@ func TestEcosystemDemo(t *testing.T) {
314307
}
315308

316309
func TestTemplatesDemo(t *testing.T) {
317-
assert2, channel, authtoken, err := createAccountAndSignIn(t)
310+
assert2, authtoken, err := createAccountAndSignIn(t)
318311
if !assert2.Nil(err) {
319312
return
320313
}
321314

322-
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel))
315+
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken))
323316
if !assert2.Nil(err) {
324317
return
325318
}

python/samples/vaccine_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ async def vaccine_demo():
119119
# print(f"Credential_status: {credential_status}")
120120
# assert credential_status.revoked is True
121121
# }
122+
credentials_service.close()
123+
wallet_service.close()
124+
account_service.close()
125+
provider_service.close()
122126

123127

124128
if __name__ == "__main__":

python/tests/test_trinsic_services.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import asyncio
22
import platform
33
import unittest
4-
import uuid
54

65
from samples.ecosystem_demo import ecosystem_demo
76
from samples.provider_demo import provider_demo
7+
from samples.templates_demo import templates_demo
88
from samples.trustregistry_demo import trustregistry_demo
99
from samples.vaccine_demo import vaccine_demo
10-
from samples.templates_demo import templates_demo
11-
from trinsic.proto.services.account.v1 import InfoResponse
12-
from trinsic.proto.services.common.v1 import ResponseStatus
13-
from trinsic.service_base import ResponseStatusException
1410
from trinsic.account_service import AccountService
11+
from trinsic.proto.services.common.v1 import ResponseStatus
1512
from trinsic.provider_service import ProviderService
16-
from trinsic.trustregistry_service import TrustRegistryService
17-
from trinsic.wallet_service import WalletService
13+
from trinsic.service_base import ResponseStatusException
1814
from trinsic.trinsic_util import trinsic_config
15+
from trinsic.trustregistry_service import TrustRegistryService
1916

2017

2118
# Due to some issues with python and async io test cases, we have to run each sample in a separate asyncio event loop.
@@ -74,7 +71,6 @@ async def test_code():
7471

7572
asyncio.run(test_code())
7673

77-
@unittest.skip("Account protection demo hangs")
7874
def test_protect_unprotect_account(self):
7975
async def test_code():
8076
account_service = AccountService(server_config=trinsic_config())
@@ -86,7 +82,7 @@ async def test_code():
8682
with self.assertRaises(Exception) as ve:
8783
await self.print_get_info(account_service, my_protected_profile)
8884

89-
my_unprotected_profile = account_service.unprotect(my_profile, code)
85+
my_unprotected_profile = account_service.unprotect(my_protected_profile, code)
9086
# This hangs for unknown reasons.
9187
await self.print_get_info(account_service, my_unprotected_profile)
9288

0 commit comments

Comments
 (0)