From cd7d75c8b42ad15eee1ac594ff6d0f2d5a75eb67 Mon Sep 17 00:00:00 2001 From: Hylke Visser Date: Tue, 8 Dec 2020 11:03:54 +0100 Subject: [PATCH] is: Migrate Is service to protobuf apiv2 --- pkg/identityserver/config.go | 61 ++++++++++++++-------------- pkg/identityserver/identityserver.go | 5 ++- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/pkg/identityserver/config.go b/pkg/identityserver/config.go index 7f88f06334..312916ff09 100644 --- a/pkg/identityserver/config.go +++ b/pkg/identityserver/config.go @@ -18,14 +18,15 @@ import ( "context" "time" - "github.com/gogo/protobuf/types" + "go.thethings.network/lorawan-stack/v3/api" "go.thethings.network/lorawan-stack/v3/pkg/config" "go.thethings.network/lorawan-stack/v3/pkg/email" "go.thethings.network/lorawan-stack/v3/pkg/email/sendgrid" "go.thethings.network/lorawan-stack/v3/pkg/email/smtp" "go.thethings.network/lorawan-stack/v3/pkg/fetch" "go.thethings.network/lorawan-stack/v3/pkg/oauth" - "go.thethings.network/lorawan-stack/v3/pkg/ttnpb" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/wrapperspb" ) // Config for the Identity Server @@ -126,46 +127,46 @@ func (c emailTemplatesConfig) Fetcher(ctx context.Context, blobConf config.BlobC } } -func (c Config) toProto() *ttnpb.IsConfiguration { - return &ttnpb.IsConfiguration{ - UserRegistration: &ttnpb.IsConfiguration_UserRegistration{ - Invitation: &ttnpb.IsConfiguration_UserRegistration_Invitation{ - Required: &types.BoolValue{Value: c.UserRegistration.Invitation.Required}, - TokenTTL: &c.UserRegistration.Invitation.TokenTTL, +func (c Config) toProto() *api.IsConfiguration { + return &api.IsConfiguration{ + UserRegistration: &api.IsConfiguration_UserRegistration{ + Invitation: &api.IsConfiguration_UserRegistration_Invitation{ + Required: &wrapperspb.BoolValue{Value: c.UserRegistration.Invitation.Required}, + TokenTtl: durationpb.New(c.UserRegistration.Invitation.TokenTTL), }, - ContactInfoValidation: &ttnpb.IsConfiguration_UserRegistration_ContactInfoValidation{ - Required: &types.BoolValue{Value: c.UserRegistration.ContactInfoValidation.Required}, + ContactInfoValidation: &api.IsConfiguration_UserRegistration_ContactInfoValidation{ + Required: &wrapperspb.BoolValue{Value: c.UserRegistration.ContactInfoValidation.Required}, }, - AdminApproval: &ttnpb.IsConfiguration_UserRegistration_AdminApproval{ - Required: &types.BoolValue{Value: c.UserRegistration.AdminApproval.Required}, + AdminApproval: &api.IsConfiguration_UserRegistration_AdminApproval{ + Required: &wrapperspb.BoolValue{Value: c.UserRegistration.AdminApproval.Required}, }, - PasswordRequirements: &ttnpb.IsConfiguration_UserRegistration_PasswordRequirements{ - MinLength: &types.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinLength)}, - MaxLength: &types.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MaxLength)}, - MinUppercase: &types.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinUppercase)}, - MinDigits: &types.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinDigits)}, - MinSpecial: &types.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinSpecial)}, + PasswordRequirements: &api.IsConfiguration_UserRegistration_PasswordRequirements{ + MinLength: &wrapperspb.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinLength)}, + MaxLength: &wrapperspb.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MaxLength)}, + MinUppercase: &wrapperspb.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinUppercase)}, + MinDigits: &wrapperspb.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinDigits)}, + MinSpecial: &wrapperspb.UInt32Value{Value: uint32(c.UserRegistration.PasswordRequirements.MinSpecial)}, }, }, - ProfilePicture: &ttnpb.IsConfiguration_ProfilePicture{ - DisableUpload: &types.BoolValue{Value: c.ProfilePicture.DisableUpload}, - UseGravatar: &types.BoolValue{Value: c.ProfilePicture.UseGravatar}, + ProfilePicture: &api.IsConfiguration_ProfilePicture{ + DisableUpload: &wrapperspb.BoolValue{Value: c.ProfilePicture.DisableUpload}, + UseGravatar: &wrapperspb.BoolValue{Value: c.ProfilePicture.UseGravatar}, }, - EndDevicePicture: &ttnpb.IsConfiguration_EndDevicePicture{ - DisableUpload: &types.BoolValue{Value: c.ProfilePicture.DisableUpload}, + EndDevicePicture: &api.IsConfiguration_EndDevicePicture{ + DisableUpload: &wrapperspb.BoolValue{Value: c.ProfilePicture.DisableUpload}, }, - UserRights: &ttnpb.IsConfiguration_UserRights{ - CreateApplications: &types.BoolValue{Value: c.UserRights.CreateApplications}, - CreateClients: &types.BoolValue{Value: c.UserRights.CreateClients}, - CreateGateways: &types.BoolValue{Value: c.UserRights.CreateGateways}, - CreateOrganizations: &types.BoolValue{Value: c.UserRights.CreateOrganizations}, + UserRights: &api.IsConfiguration_UserRights{ + CreateApplications: &wrapperspb.BoolValue{Value: c.UserRights.CreateApplications}, + CreateClients: &wrapperspb.BoolValue{Value: c.UserRights.CreateClients}, + CreateGateways: &wrapperspb.BoolValue{Value: c.UserRights.CreateGateways}, + CreateOrganizations: &wrapperspb.BoolValue{Value: c.UserRights.CreateOrganizations}, }, } } // GetConfiguration implements the RPC that returns the configuration of the Identity Server. -func (is *IdentityServer) GetConfiguration(ctx context.Context, _ *ttnpb.GetIsConfigurationRequest) (*ttnpb.GetIsConfigurationResponse, error) { - return &ttnpb.GetIsConfigurationResponse{ +func (is *IdentityServer) GetConfiguration(ctx context.Context, _ *api.GetIsConfigurationRequest) (*api.GetIsConfigurationResponse, error) { + return &api.GetIsConfigurationResponse{ Configuration: is.configFromContext(ctx).toProto(), }, nil } diff --git a/pkg/identityserver/identityserver.go b/pkg/identityserver/identityserver.go index 025690929f..13065795b1 100644 --- a/pkg/identityserver/identityserver.go +++ b/pkg/identityserver/identityserver.go @@ -20,6 +20,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/postgres" // Postgres database driver. + "go.thethings.network/lorawan-stack/v3/api" "go.thethings.network/lorawan-stack/v3/pkg/auth/rights" "go.thethings.network/lorawan-stack/v3/pkg/cluster" "go.thethings.network/lorawan-stack/v3/pkg/component" @@ -47,6 +48,8 @@ type IdentityServer struct { redis *redis.Client emailTemplates *email.TemplateRegistry oauth oauth.Server + + api.UnimplementedIsServer } // Context returns the context of the Identity Server. @@ -158,7 +161,7 @@ func (is *IdentityServer) withDatabase(ctx context.Context, f func(*gorm.DB) err // RegisterServices registers services provided by is at s. func (is *IdentityServer) RegisterServices(s *grpc.Server) { - ttnpb.RegisterIsServer(s, is) + api.RegisterIsServer(s, is) ttnpb.RegisterEntityAccessServer(s, &entityAccess{IdentityServer: is}) ttnpb.RegisterApplicationRegistryServer(s, &applicationRegistry{IdentityServer: is}) ttnpb.RegisterApplicationAccessServer(s, &applicationAccess{IdentityServer: is})