Skip to content

Commit

Permalink
is: Migrate Is service to protobuf apiv2
Browse files Browse the repository at this point in the history
  • Loading branch information
htdvisser committed Dec 8, 2020
1 parent 15ca9b8 commit cd7d75c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
61 changes: 31 additions & 30 deletions pkg/identityserver/config.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion pkg/identityserver/identityserver.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit cd7d75c

Please sign in to comment.