Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ jobs:
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
LD_LIBRARY_PATH: "${{ github.workspace }}/libs"
TEST_SERVER_ENDPOINT: ${{ secrets.TEST_SERVER_ENDPOINT }}
TEST_SERVER_PORT: ${{ secrets.TEST_SERVER_PORT }}
TEST_SERVER_USE_TLS: ${{ secrets.TEST_SERVER_USE_TLS }}
# TEST_SERVER_PORT: ${{ secrets.TEST_SERVER_PORT }}
# TEST_SERVER_USE_TLS: ${{ secrets.TEST_SERVER_USE_TLS }}
- name: Upload Unit Test Results - Python
if: always()
uses: actions/upload-artifact@v2
Expand Down
1 change: 1 addition & 0 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/trinsic-id/sdk/go
go 1.16

require (
github.com/google/uuid v1.3.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/trinsic-id/okapi/go v1.4.0
google.golang.org/grpc v1.41.0
Expand Down
2 changes: 2 additions & 0 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down
3 changes: 3 additions & 0 deletions go/services/account_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func (a *accountBase) SignIn(userContext context.Context, request *sdk.SignInReq
if request == nil {
request = &sdk.SignInRequest{}
}
if request.Details == nil {
request.Details = &sdk.AccountDetails{}
}

if len(request.EcosystemId) == 0 {
request.EcosystemId = a.GetServiceOptions().DefaultEcosystem
Expand Down
18 changes: 8 additions & 10 deletions go/services/service_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,23 @@ import (
// NewServiceBase returns a base service which is the foundation
// for all the other services
func NewServiceBase(options *Options) (Service, error) {
if options.Channel == nil {
conn, err := NewServiceConnection(options.ServiceOptions)
if err != nil {
return nil, err
}

options.Channel = conn
conn, err := NewServiceConnection(options.ServiceOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've made the base class private so that access to the channel property is no longer accessible. Are we not allowing developers to provide a grpc connection for re-use?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed the channel as direct dependency from service construction to simplify what we pass, but channel is still available for reuse.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good - the way the WithChannel option was handled was to use the channel if provided, and if not we would create a default one.

I understand there could be some confusion if a developer provided both a grpc connection and a "connection config", since we use the provided connection and ignore the config. That being said, I would think a developer who needed to provide a custom grpc connection would not be confused when that was used (the expected behaviour) vs. the config they provided (if they did).

My confusion was just around removing the WithChannel option - since the base implementations are now private channel reuse in golang is no longer possible (you can get the channel, but you cannot provide that to another service when constructing it).

if err != nil {
return nil, err
}

return &serviceBase{
options: options,
channel: conn,
securityProvider: &OberonSecurityProvider{},
}, nil
}

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

type serviceBase struct {
options *Options
channel *grpc.ClientConn
securityProvider SecurityProvider
}

func (s *serviceBase) GetChannel() *grpc.ClientConn {
return s.options.Channel
return s.channel
}

func (s *serviceBase) SetToken(authtoken string) {
Expand Down
3 changes: 1 addition & 2 deletions go/services/service_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestServiceBase(t *testing.T) {
ServerPort: 1234,
DefaultEcosystem: "test"},
),
WithChannel(nconn),
)

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

// we should have an empty auth profile
assert.Empty(base.GetProfile(), "auth Profile should be empty")
Expand Down
20 changes: 8 additions & 12 deletions go/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import (
"strings"

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

//Options for configuring the sdk
type Options struct {
ServiceOptions *sdk.ServiceOptions
Channel *grpc.ClientConn
}

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

useTLS := os.Getenv("TEST_SERVER_USE_TLS")
if len(useTLS) != 0 && strings.Compare(strings.ToLower(useTLS), "false") != 0 {
s.ServiceOptions.ServerUseTls = true
} else {
if len(useTLS) != 0 && strings.Compare(strings.ToLower(useTLS), "false") == 0 {
s.ServiceOptions.ServerUseTls = false
} else {
s.ServiceOptions.ServerUseTls = true
}

return nil
}
}
defaultEcosystem := os.Getenv("TEST_SERVER_ECOSYSTEM")
if len(defaultEcosystem) > 0 {
} else {
s.ServiceOptions.DefaultEcosystem = "default"
}

// WithChannel will use the provided grpc channel instead of creating a default
func WithChannel(conn *grpc.ClientConn) Option {
return func(s *Options) error {
s.Channel = conn
return nil
}
}
37 changes: 15 additions & 22 deletions go/services/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"runtime"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
sdk "github.com/trinsic-id/sdk/go/proto"
"google.golang.org/grpc"
)

// pathData() {
Expand Down Expand Up @@ -63,11 +63,6 @@ func TestServiceOptions(t *testing.T) {
func TestVaccineCredentialsDemo(t *testing.T) {
assert2 := assert.New(t)

err := createDefaultEcosystem()
if !assert2.Nil(err) {
return
}

// Open in background
opts, err := NewServiceOptions(WithTestEnv())
if !assert2.Nil(err) {
Expand All @@ -79,8 +74,6 @@ func TestVaccineCredentialsDemo(t *testing.T) {
return
}

opts.Channel = accountService.GetChannel()

// if !accountService.GetChannel().WaitForStateChange(context.Background(), connectivity.Ready) {
// t.Fail()
// }
Expand Down Expand Up @@ -180,12 +173,12 @@ func TestVaccineCredentialsDemo(t *testing.T) {
}

func TestTrustRegistryDemo(t *testing.T) {
assert2, channel, authtoken, err := createAccountAndSignIn(t)
assert2, authtoken, err := createAccountAndSignIn(t)
if !assert2.Nil(err) {
return
}

opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel))
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken))
if !assert2.Nil(err) {
return
}
Expand Down Expand Up @@ -242,26 +235,26 @@ func TestTrustRegistryDemo(t *testing.T) {
assert2.NotEmpty(ecosystemList)
}

func createAccountAndSignIn(t *testing.T) (*assert.Assertions, *grpc.ClientConn, string, error) {
func createAccountAndSignIn(t *testing.T) (*assert.Assertions, string, error) {
assert2 := assert.New(t)
opts, err := NewServiceOptions(WithTestEnv())
if !assert2.Nil(err) {
return assert2, nil, "", err
return assert2, "", err
}
// Open in background
accountService, err := NewAccountService(opts)
if !assert2.Nil(err) {
return assert2, nil, "", err
return assert2, "", err
}
authtoken, _, err := accountService.SignIn(context.Background(), &sdk.SignInRequest{})
if !assert2.Nil(err) {
fmt.Println(err)
return assert2, nil, "", err
return assert2, "", err
}
return assert2, accountService.GetChannel(), authtoken, nil
return assert2, authtoken, nil
}

func createDefaultEcosystem() error {
func createRandomEcosystem() error {
opts, err := NewServiceOptions(WithTestEnv())
if err != nil {
return err
Expand All @@ -272,17 +265,17 @@ func createDefaultEcosystem() error {
return err
}

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

return err
}
func TestEcosystemDemo(t *testing.T) {
assert2, channel, authtoken, err := createAccountAndSignIn(t)
assert2, authtoken, err := createAccountAndSignIn(t)
if !assert2.Nil(err) {
return
}

opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel))
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken))
if !assert2.Nil(err) {
return
}
Expand All @@ -293,7 +286,7 @@ func TestEcosystemDemo(t *testing.T) {
}

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

func TestTemplatesDemo(t *testing.T) {
assert2, channel, authtoken, err := createAccountAndSignIn(t)
assert2, authtoken, err := createAccountAndSignIn(t)
if !assert2.Nil(err) {
return
}

opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken), WithChannel(channel))
opts, err := NewServiceOptions(WithTestEnv(), WithAuthToken(authtoken))
if !assert2.Nil(err) {
return
}
Expand Down
4 changes: 4 additions & 0 deletions python/samples/vaccine_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ async def vaccine_demo():
# print(f"Credential_status: {credential_status}")
# assert credential_status.revoked is True
# }
credentials_service.close()
wallet_service.close()
account_service.close()
provider_service.close()


if __name__ == "__main__":
Expand Down
14 changes: 5 additions & 9 deletions python/tests/test_trinsic_services.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import asyncio
import platform
import unittest
import uuid

from samples.ecosystem_demo import ecosystem_demo
from samples.provider_demo import provider_demo
from samples.templates_demo import templates_demo
from samples.trustregistry_demo import trustregistry_demo
from samples.vaccine_demo import vaccine_demo
from samples.templates_demo import templates_demo
from trinsic.proto.services.account.v1 import InfoResponse
from trinsic.proto.services.common.v1 import ResponseStatus
from trinsic.service_base import ResponseStatusException
from trinsic.account_service import AccountService
from trinsic.proto.services.common.v1 import ResponseStatus
from trinsic.provider_service import ProviderService
from trinsic.trustregistry_service import TrustRegistryService
from trinsic.wallet_service import WalletService
from trinsic.service_base import ResponseStatusException
from trinsic.trinsic_util import trinsic_config
from trinsic.trustregistry_service import TrustRegistryService


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

asyncio.run(test_code())

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

my_unprotected_profile = account_service.unprotect(my_profile, code)
my_unprotected_profile = account_service.unprotect(my_protected_profile, code)
# This hangs for unknown reasons.
await self.print_get_info(account_service, my_unprotected_profile)

Expand Down