Signed-off-by: Nikolai Rodionov <allanger@badhouseplants.net>
This commit is contained in:
@@ -4,12 +4,11 @@ import (
|
||||
"context"
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/tools/logger"
|
||||
accounts "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"google.golang.org/grpc"
|
||||
"golang.org/x/oauth2"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
@@ -25,54 +24,50 @@ type AccountsNoAuthServer struct {
|
||||
ctrl *controllers.AccountController
|
||||
}
|
||||
|
||||
// SignUp should create a new user and return JWT tokens so the sessions is active right after registration
|
||||
func (a *AccountsNoAuthServer) SignUp(ctx context.Context, in *accounts.SignUpRequest) (*empty.Empty, error) {
|
||||
log := logger.FromContext(ctx)
|
||||
data := &controllers.AccountData{
|
||||
Username: in.Data.GetName(),
|
||||
Password: in.Password.GetPassword(),
|
||||
Email: in.Data.GetEmail(),
|
||||
}
|
||||
|
||||
uuid, err := a.ctrl.Create(ctx, data)
|
||||
func (a *AccountsNoAuthServer) SignIn(ctx context.Context, in *accounts.SignInRequest) (*empty.Empty, error) {
|
||||
provider, err := oidc.NewProvider(ctx, "https://authentik.badhouseplants.net")
|
||||
if err != nil {
|
||||
log.Error(err, "Couldn't create a user")
|
||||
return nil, status.Error(codes.Aborted, "user can't be created")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
accessToken, err := a.ctrl.GenerateAccessToken(uuid)
|
||||
// Configure an OpenID Connect aware OAuth2 client.
|
||||
oauth2Config := oauth2.Config{
|
||||
ClientID: "softplayer-localhost",
|
||||
ClientSecret: "pRpe3scGUE2jNH6t5rqI9R4OROeQHs4eO6ku957mYjDumKhQGX8QJcO0BMJ2FG4sUpvFrqccEqWgc3wKMp94tC8LyvTnkPF0Tg0CaldAEHuoQQdNKAzXVxwrHE6kNyBC",
|
||||
RedirectURL: "http://localhost:8080/#/auth/callback",
|
||||
|
||||
// Discovery returns the OAuth2 endpoints.
|
||||
Endpoint: provider.Endpoint(),
|
||||
|
||||
// "openid" is a required scope for OpenID Connect flows.
|
||||
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
|
||||
}
|
||||
verifier := provider.Verifier(&oidc.Config{ClientID: "softplayer-localhost"})
|
||||
|
||||
oauth2Token, err := oauth2Config.Exchange(ctx, in.Code)
|
||||
if err != nil {
|
||||
log.Error(err, "Couldn't generate an access token")
|
||||
return nil, status.Error(codes.Aborted, "Couldn't generate Access Token")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
refreshToken, err := a.ctrl.GenerateRefreshToken(ctx, uuid)
|
||||
// Extract the ID Token from OAuth2 token.
|
||||
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
|
||||
if !ok {
|
||||
return nil, status.Error(codes.Unauthenticated, "Couldn't parse oauth token")
|
||||
}
|
||||
|
||||
// Parse and verify ID Token payload.
|
||||
idToken, err := verifier.Verify(ctx, rawIDToken)
|
||||
if err != nil {
|
||||
log.Error(err, "Couldn't generate a refresh token")
|
||||
return nil, status.Error(codes.Aborted, "Couldn't generate Access Token")
|
||||
return nil, status.Error(codes.Unauthenticated, "Couldn't verify oauth token")
|
||||
}
|
||||
|
||||
header := metadata.Pairs(
|
||||
"access-token", accessToken,
|
||||
"refreshToken", refreshToken,
|
||||
)
|
||||
|
||||
if err := grpc.SetHeader(ctx, header); err != nil {
|
||||
log.Error(err, "Couldn't set headers")
|
||||
return nil, status.Error(codes.Unknown, "Couldn't set headers")
|
||||
// Extract custom claims
|
||||
var claims struct {
|
||||
Email string `json:"email"`
|
||||
Verified bool `json:"email_verified"`
|
||||
}
|
||||
if err := idToken.Claims(&claims); err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (a *AccountsNoAuthServer) SignIn(ctx context.Context, in *accounts.SignInRequest) (*empty.Empty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
func (a *AccountsNoAuthServer) ResetPassword(ctx context.Context, in *accounts.ResetPasswordRequest) (*empty.Empty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
func (acc *AccountsNoAuthServer) NewPassword(ctx context.Context, in *accounts.NewPasswordRequest) (*empty.Empty, error) {
|
||||
return nil, status.Error(codes.Unimplemented, "Endpoint is not implemented")
|
||||
}
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
proto "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/applications/v1"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
func NewApplicationsGrpcImpl(controller ctrl.Manager, log logr.Logger) *ApplicationServer {
|
||||
return &ApplicationServer{
|
||||
controller: controller,
|
||||
logInstance: log,
|
||||
}
|
||||
}
|
||||
|
||||
type ApplicationServer struct {
|
||||
proto.UnimplementedApplicationsServer
|
||||
controller ctrl.Manager
|
||||
logInstance logr.Logger
|
||||
}
|
||||
|
||||
// Create an environment
|
||||
func (app *ApplicationServer) Create(ctx context.Context, in *proto.CreateOptions) (*proto.ApplicationFull, error) {
|
||||
log := app.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid(), "environment_id", in.GetSpec().GetEnvironemntId(), "app_name", in.GetSpec().GetApplication())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
data := &controllers.ApplicationData{
|
||||
Name: in.Metadata.Name,
|
||||
Application: in.Spec.Application,
|
||||
Version: in.Spec.Version,
|
||||
Environemnt: in.Spec.EnvironemntId,
|
||||
Config: in.Spec.Config,
|
||||
RawConfig: "",
|
||||
}
|
||||
|
||||
application := &controllers.Application{
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: app.controller,
|
||||
Data: data,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
err := application.Create(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &proto.ApplicationFull{
|
||||
Metadata: in.GetMetadata(),
|
||||
Id: &proto.ApplicationId{
|
||||
Uuid: application.Data.UUID,
|
||||
},
|
||||
Spec: in.GetSpec(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (app *ApplicationServer) Delete(ctx context.Context, in *proto.DeleteOptions) (*empty.Empty, error) {
|
||||
log := app.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid(), "app_id", in.GetId().GetUuid())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
data := &controllers.ApplicationData{
|
||||
Name: in.Metadata.Name,
|
||||
UUID: in.GetId().GetUuid(),
|
||||
}
|
||||
|
||||
application := &controllers.Application{
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: app.controller,
|
||||
Data: data,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
err := application.Delete(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/helpers/email"
|
||||
proto_email "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/email/v1"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
type EmailServer struct {
|
||||
proto_email.UnimplementedEmailValidationServer
|
||||
emailConfig email.EmailConf
|
||||
controller ctrl.Manager
|
||||
// When dev mode is enabled, email won't be sent, instead the code will be returned in metadata
|
||||
devMode bool
|
||||
}
|
||||
|
||||
func InitEmailServer(controller ctrl.Manager, emailConfig *email.EmailConf, devMode bool) *EmailServer {
|
||||
return &EmailServer{
|
||||
controller: controller,
|
||||
emailConfig: *emailConfig,
|
||||
devMode: devMode,
|
||||
}
|
||||
}
|
||||
|
||||
// Send the validation code to email
|
||||
func (c *EmailServer) SendRequest(ctx context.Context, in *proto_email.RequestValidation) (*emptypb.Empty, error) {
|
||||
// Validation
|
||||
if len(in.GetUserId()) == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "user id must not be empty")
|
||||
}
|
||||
|
||||
// Body
|
||||
emailSvc := controllers.EmailSvc{
|
||||
Data: controllers.EmailData{
|
||||
UserID: in.GetUserId(),
|
||||
},
|
||||
EmailConfig: c.emailConfig,
|
||||
Controller: c.controller,
|
||||
DevMode: c.devMode,
|
||||
}
|
||||
err := emailSvc.SendVerification(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.devMode {
|
||||
header := metadata.Pairs("code", emailSvc.Data.Code)
|
||||
if err := grpc.SendHeader(ctx, header); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (c *EmailServer) ValidateEmail(ctx context.Context, in *proto_email.ConfirmValidation) (*emptypb.Empty, error) {
|
||||
// Validation
|
||||
if len(in.GetUserId()) == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "user id must not be empty")
|
||||
}
|
||||
if in.GetCode() == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "code must not be empty")
|
||||
}
|
||||
|
||||
// Body
|
||||
emailSvc := controllers.EmailSvc{
|
||||
Data: controllers.EmailData{
|
||||
UserID: in.GetUserId(),
|
||||
Code: fmt.Sprintf("%d", in.GetCode()),
|
||||
},
|
||||
EmailConfig: c.emailConfig,
|
||||
Controller: c.controller,
|
||||
}
|
||||
err := emailSvc.ConfirmVerification(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/providers/infra"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/providers/kubernetes"
|
||||
proto "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments/v1"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
func NewapiGrpcImpl(controller ctrl.Manager, log logr.Logger) *EnvironmentsServer {
|
||||
return &EnvironmentsServer{
|
||||
controller: controller,
|
||||
logInstance: log,
|
||||
}
|
||||
}
|
||||
|
||||
type EnvironmentsServer struct {
|
||||
proto.UnimplementedEnvironmentsServer
|
||||
controller ctrl.Manager
|
||||
logInstance logr.Logger
|
||||
}
|
||||
|
||||
// Create an environment
|
||||
func (e *EnvironmentsServer) Create(ctx context.Context, in *proto.CreateOptions) (*proto.EnvironmentFull, error) {
|
||||
log := e.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
provider, err := infra.GetProvider(in.GetSpec().GetProvider().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8s, err := kubernetes.GetKubernetes(in.GetSpec().GetKubernetes().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
location, err := provider.GetServerLocation(in.GetSpec().GetServerLocation().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
serverType, err := provider.GetServerType(in.Spec.ServerType.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := &controllers.EnvironemntData{
|
||||
Name: in.GetMetadata().GetName(),
|
||||
Description: in.GetMetadata().GetDescription(),
|
||||
Provider: provider.GetProviderName(),
|
||||
Kubernetes: k8s.GetKubernetesName(),
|
||||
Location: location,
|
||||
ServerType: serverType,
|
||||
DiskSize: int(in.GetSpec().GetDiskSize()),
|
||||
}
|
||||
|
||||
environment := &controllers.Environemnt{
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Config: ctrl.GetConfigOrDie(),
|
||||
Controller: e.controller,
|
||||
Data: data,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
err = environment.Create(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &proto.EnvironmentFull{
|
||||
Metadata: in.GetMetadata(),
|
||||
Id: &proto.EnvironmentId{
|
||||
Uuid: environment.Data.UUID,
|
||||
},
|
||||
Spec: in.GetSpec(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.UpdateOptions) (*proto.EnvironmentFull, error) {
|
||||
log := e.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
provider, err := infra.GetProvider(in.GetSpec().GetProvider().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8s, err := kubernetes.GetKubernetes(in.GetSpec().GetKubernetes().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
location, err := provider.GetServerLocation(in.GetSpec().GetServerLocation().String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
serverType, err := provider.GetServerType(in.Spec.ServerType.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data := &controllers.EnvironemntData{
|
||||
Name: in.GetMetadata().GetName(),
|
||||
UUID: in.GetId().GetUuid(),
|
||||
Description: in.GetMetadata().GetDescription(),
|
||||
Provider: provider.GetProviderName(),
|
||||
Kubernetes: k8s.GetKubernetesName(),
|
||||
Location: location,
|
||||
ServerType: serverType,
|
||||
DiskSize: int(in.GetSpec().GetDiskSize()),
|
||||
}
|
||||
|
||||
environment := &controllers.Environemnt{
|
||||
Config: ctrl.GetConfigOrDie(),
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: e.controller,
|
||||
Data: data,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
err = environment.Update(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &proto.EnvironmentFull{
|
||||
Metadata: in.GetMetadata(),
|
||||
Id: in.GetId(),
|
||||
Spec: in.GetSpec(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.DeleteOptions) (*empty.Empty, error) {
|
||||
log := e.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
data := &controllers.EnvironemntData{
|
||||
Name: in.GetMetadata().GetName(),
|
||||
UUID: in.GetId().GetUuid(),
|
||||
}
|
||||
|
||||
environment := &controllers.Environemnt{
|
||||
Config: ctrl.GetConfigOrDie(),
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: e.controller,
|
||||
Data: data,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
err := environment.Delete(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (e *EnvironmentsServer) Get(ctx context.Context, in *proto.GetOptions) (*proto.EnvironmentFull, error) {
|
||||
log := e.logInstance
|
||||
log.WithValues("user_id", in.GetOwnerId().GetUuid())
|
||||
ctx = logr.NewContext(ctx, log)
|
||||
|
||||
data := &controllers.EnvironemntData{
|
||||
UUID: in.GetId().GetUuid(),
|
||||
}
|
||||
|
||||
environment := &controllers.Environemnt{
|
||||
Config: ctrl.GetConfigOrDie(),
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: e.controller,
|
||||
Data: data,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
if err := environment.Get(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
provider, err := infra.GetProvider(environment.Data.Provider)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
k8s, err := kubernetes.GetKubernetes(environment.Data.Kubernetes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &proto.EnvironmentFull{
|
||||
Spec: &proto.EnvironmentSpec{
|
||||
Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]),
|
||||
Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]),
|
||||
ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(environment.Data.Location)]),
|
||||
ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(environment.Data.ServerType)]),
|
||||
DiskSize: int32(environment.Data.DiskSize),
|
||||
},
|
||||
Id: in.GetId(),
|
||||
Metadata: &proto.EnvironmentMetadata{
|
||||
Name: environment.Data.Name,
|
||||
Description: environment.Data.Description,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *EnvironmentsServer) List(in *proto.ListOptions, stream proto.Environments_ListServer) error {
|
||||
logInstance := e.logInstance
|
||||
log := logInstance.WithValues("user_id", in.GetOwnerId().GetUuid())
|
||||
ctx := logr.NewContext(stream.Context(), log)
|
||||
|
||||
environment := &controllers.Environemnt{
|
||||
Config: ctrl.GetConfigOrDie(),
|
||||
UserID: in.GetOwnerId().GetUuid(),
|
||||
Controller: e.controller,
|
||||
Token: in.GetToken().GetToken(),
|
||||
}
|
||||
|
||||
envs, err := environment.List(ctx, in.GetSearchString())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, env := range envs {
|
||||
provider, err := infra.GetProvider(env.Data.Provider)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
k8s, err := kubernetes.GetKubernetes(env.Data.Kubernetes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := stream.Send(&proto.EnvironmentFull{
|
||||
Metadata: &proto.EnvironmentMetadata{
|
||||
Name: env.Data.Name,
|
||||
Description: env.Data.Description,
|
||||
},
|
||||
Id: &proto.EnvironmentId{
|
||||
Uuid: env.Data.UUID,
|
||||
},
|
||||
Spec: &proto.EnvironmentSpec{
|
||||
Provider: proto.Provider(proto.Provider_value[provider.RawProviderName()]),
|
||||
Kubernetes: proto.Kubernetes(proto.Kubernetes_value[k8s.RawKubernetesName()]),
|
||||
ServerLocation: proto.Location(proto.Location_value[provider.RawServerLocation(env.Data.Location)]),
|
||||
ServerType: proto.ServerType(proto.ServerType_value[provider.RawServerType(env.Data.ServerType)]),
|
||||
DiskSize: int32(env.Data.DiskSize),
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
22
api/v1/test_auth.go
Normal file
22
api/v1/test_auth.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/tools/logger"
|
||||
test "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/test/v1"
|
||||
)
|
||||
|
||||
func NewTestAuthRPCImpl() *TestAuthServer {
|
||||
return &TestAuthServer{}
|
||||
}
|
||||
|
||||
type TestAuthServer struct {
|
||||
test.UnimplementedTestAuthServiceServer
|
||||
}
|
||||
|
||||
func (t *TestAuthServer) Pong(ctx context.Context, in *test.PongRequest) (*test.PongResponse, error) {
|
||||
log := logger.FromContext(ctx)
|
||||
log.Info("Pong")
|
||||
return &test.PongResponse{}, nil
|
||||
}
|
||||
22
api/v1/test_no_auth.go
Normal file
22
api/v1/test_no_auth.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/tools/logger"
|
||||
test "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/test/v1"
|
||||
)
|
||||
|
||||
func NewTestNoAuthRPCImpl() *TestNoAuthServer {
|
||||
return &TestNoAuthServer{}
|
||||
}
|
||||
|
||||
type TestNoAuthServer struct {
|
||||
test.UnimplementedTestNoAuthServiceServer
|
||||
}
|
||||
|
||||
func (t *TestNoAuthServer) Ping(ctx context.Context, in *test.PingRequest) (*test.PingResponse, error) {
|
||||
log := logger.FromContext(ctx)
|
||||
log.Info("Ping")
|
||||
return &test.PingResponse{}, nil
|
||||
}
|
||||
6
go.mod
6
go.mod
@@ -5,6 +5,7 @@ go 1.25.9
|
||||
require (
|
||||
github.com/alecthomas/assert/v2 v2.11.0
|
||||
github.com/alecthomas/kong v1.15.0
|
||||
github.com/coreos/go-oidc/v3 v3.18.0
|
||||
github.com/go-logr/logr v1.4.3
|
||||
github.com/go-logr/zapr v1.3.0
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2
|
||||
@@ -19,6 +20,7 @@ require (
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/crypto v0.47.0
|
||||
golang.org/x/oauth2 v0.36.0
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
helm.sh/helm/v3 v3.20.2
|
||||
k8s.io/api v0.35.1
|
||||
@@ -58,6 +60,7 @@ require (
|
||||
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
|
||||
github.com/go-errors/errors v1.4.2 // indirect
|
||||
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.21.0 // indirect
|
||||
github.com/go-openapi/jsonreference v0.21.0 // indirect
|
||||
github.com/go-openapi/swag v0.23.0 // indirect
|
||||
@@ -112,7 +115,6 @@ require (
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/oauth2 v0.34.0 // indirect
|
||||
golang.org/x/sync v0.19.0 // indirect
|
||||
golang.org/x/term v0.39.0 // indirect
|
||||
golang.org/x/time v0.12.0 // indirect
|
||||
@@ -138,7 +140,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260428191411-8c93fd05025a
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260430152421-88c087f0cea0
|
||||
github.com/golang/protobuf v1.5.4
|
||||
golang.org/x/net v0.49.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
|
||||
12
go.sum
12
go.sum
@@ -6,8 +6,8 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
|
||||
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260428191411-8c93fd05025a h1:8Mo14FqMkUcUNyyVfrTGZOe/BHn412olquEDqL+Fg6c=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260428191411-8c93fd05025a/go.mod h1:AgOh1lkPHyRgBf3/s1btKcAqke/33LbKYarTD13qeAg=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260430152421-88c087f0cea0 h1:2UggBAWgOJ1MYgkk+RTaWhfTGtzAZ0B9MriZMoHqnq4=
|
||||
gitea.badhouseplants.net/softplayer/softplayer-go-proto v0.0.0-20260430152421-88c087f0cea0/go.mod h1:AgOh1lkPHyRgBf3/s1btKcAqke/33LbKYarTD13qeAg=
|
||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
|
||||
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c h1:udKWzYgxTojEKWjV8V+WSxDXJ4NFATAsZjh8iIbsQIg=
|
||||
@@ -66,6 +66,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
|
||||
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
|
||||
github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A=
|
||||
github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw=
|
||||
github.com/coreos/go-oidc/v3 v3.18.0 h1:V9orjXynvu5wiC9SemFTWnG4F45v403aIcjWo0d41+A=
|
||||
github.com/coreos/go-oidc/v3 v3.18.0/go.mod h1:DYCf24+ncYi+XkIH97GY1+dqoRlbaSI26KVTCI9SrY4=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
@@ -127,6 +129,8 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI
|
||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||
github.com/go-gorp/gorp/v3 v3.1.0 h1:ItKF/Vbuj31dmV4jxA1qblpSwkl9g1typ24xoe70IGs=
|
||||
github.com/go-gorp/gorp/v3 v3.1.0/go.mod h1:dLEjIyyRNiXvNZ8PSmzpt1GsWAUK8kjVhEpjH8TixEw=
|
||||
github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
|
||||
github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
@@ -435,8 +439,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.34.0 h1:hqK/t4AKgbqWkdkcAeI8XLmbK+4m4G5YeQRrmiotGlw=
|
||||
golang.org/x/oauth2 v0.34.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
|
||||
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
|
||||
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
|
||||
4
main.go
4
main.go
@@ -13,6 +13,7 @@ import (
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/controllers"
|
||||
"gitea.badhouseplants.net/softplayer/softplayer-backend/internal/tools/logger"
|
||||
accounts "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/accounts/v1"
|
||||
test "gitea.badhouseplants.net/softplayer/softplayer-go-proto/pkg/test/v1"
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
@@ -213,7 +214,8 @@ func server(ctx context.Context, params Serve) error {
|
||||
}
|
||||
accounts.RegisterAccountsNoAuthServiceServer(grpcServer, v1.NewAccountNoAuthRPCImpl(accountCtrl))
|
||||
accounts.RegisterAccountsAuthServiceServer(grpcServer, v1.NewAccountAuthRPCImpl(accountCtrl))
|
||||
|
||||
test.RegisterTestAuthServiceServer(grpcServer, v1.NewTestAuthRPCImpl())
|
||||
test.RegisterTestNoAuthServiceServer(grpcServer, v1.NewTestNoAuthRPCImpl())
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user