mirror of
https://github.com/MizuchiLabs/mantrae.git
synced 2025-12-16 20:05:17 -06:00
fix restore and profile tokens
This commit is contained in:
@@ -46,6 +46,13 @@ func (s *ProfileService) CreateProfile(
|
||||
if err != nil {
|
||||
return nil, connect.NewError(connect.CodeInternal, err)
|
||||
}
|
||||
|
||||
s.app.Event.Broadcast(&mantraev1.EventStreamResponse{
|
||||
Action: mantraev1.EventAction_EVENT_ACTION_CREATED,
|
||||
Data: &mantraev1.EventStreamResponse_Profile{
|
||||
Profile: result.ToProto(),
|
||||
},
|
||||
})
|
||||
return connect.NewResponse(&mantraev1.CreateProfileResponse{
|
||||
Profile: result.ToProto(),
|
||||
}), nil
|
||||
@@ -62,12 +69,25 @@ func (s *ProfileService) UpdateProfile(
|
||||
}
|
||||
if req.Msg.GetRegenerateToken() {
|
||||
params.Token = util.GenerateToken(6)
|
||||
} else {
|
||||
profile, err := s.app.Conn.GetQuery().GetProfile(ctx, params.ID)
|
||||
if err != nil {
|
||||
return nil, connect.NewError(connect.CodeInternal, err)
|
||||
}
|
||||
params.Token = profile.Token
|
||||
}
|
||||
|
||||
result, err := s.app.Conn.GetQuery().UpdateProfile(ctx, params)
|
||||
if err != nil {
|
||||
return nil, connect.NewError(connect.CodeInternal, err)
|
||||
}
|
||||
|
||||
s.app.Event.Broadcast(&mantraev1.EventStreamResponse{
|
||||
Action: mantraev1.EventAction_EVENT_ACTION_UPDATED,
|
||||
Data: &mantraev1.EventStreamResponse_Profile{
|
||||
Profile: result.ToProto(),
|
||||
},
|
||||
})
|
||||
return connect.NewResponse(&mantraev1.UpdateProfileResponse{
|
||||
Profile: result.ToProto(),
|
||||
}), nil
|
||||
@@ -77,9 +97,20 @@ func (s *ProfileService) DeleteProfile(
|
||||
ctx context.Context,
|
||||
req *connect.Request[mantraev1.DeleteProfileRequest],
|
||||
) (*connect.Response[mantraev1.DeleteProfileResponse], error) {
|
||||
profile, err := s.app.Conn.GetQuery().GetProfile(ctx, req.Msg.Id)
|
||||
if err != nil {
|
||||
return nil, connect.NewError(connect.CodeInternal, err)
|
||||
}
|
||||
if err := s.app.Conn.GetQuery().DeleteProfile(ctx, req.Msg.Id); err != nil {
|
||||
return nil, connect.NewError(connect.CodeInternal, err)
|
||||
}
|
||||
|
||||
s.app.Event.Broadcast(&mantraev1.EventStreamResponse{
|
||||
Action: mantraev1.EventAction_EVENT_ACTION_DELETED,
|
||||
Data: &mantraev1.EventStreamResponse_Profile{
|
||||
Profile: profile.ToProto(),
|
||||
},
|
||||
})
|
||||
return connect.NewResponse(&mantraev1.DeleteProfileResponse{}), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mizuchilabs/mantrae/server/internal/storage"
|
||||
"github.com/mizuchilabs/mantrae/server/internal/store/db"
|
||||
"github.com/mizuchilabs/mantrae/server/internal/store/schema"
|
||||
@@ -201,6 +202,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
entryPointSet[ep] = db.CreateEntryPointParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: ep,
|
||||
IsDefault: false,
|
||||
@@ -215,6 +217,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateHttpRouter(ctx, db.CreateHttpRouterParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapRouter(v),
|
||||
@@ -228,6 +231,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateHttpService(ctx, db.CreateHttpServiceParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapService(v),
|
||||
@@ -240,6 +244,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateHttpMiddleware(ctx, db.CreateHttpMiddlewareParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapMiddleware(v),
|
||||
@@ -254,6 +259,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateTcpRouter(ctx, db.CreateTcpRouterParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapTCPRouter(v),
|
||||
@@ -267,6 +273,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateTcpService(ctx, db.CreateTcpServiceParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapTCPService(v),
|
||||
@@ -293,6 +300,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateUdpRouter(ctx, db.CreateUdpRouterParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapUDPRouter(v),
|
||||
@@ -306,6 +314,7 @@ func DynamicToDB(
|
||||
continue
|
||||
}
|
||||
if _, err := q.CreateUdpService(ctx, db.CreateUdpServiceParams{
|
||||
ID: uuid.New().String(),
|
||||
ProfileID: profileID,
|
||||
Name: k,
|
||||
Config: schema.WrapUDPService(v),
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<script lang="ts">
|
||||
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
||||
import { buildConnectionString, profileClient } from '$lib/api';
|
||||
import { Button } from '$lib/components/ui/button/index.js';
|
||||
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import Separator from '../ui/separator/separator.svelte';
|
||||
import type { Profile } from '$lib/gen/mantrae/v1/profile_pb';
|
||||
import { buildConnectionString, profileClient } from '$lib/api';
|
||||
import { ConnectError } from '@connectrpc/connect';
|
||||
import { profile as profileStore } from '$lib/stores/profile';
|
||||
import CopyInput from '../ui/copy-input/copy-input.svelte';
|
||||
import { ConnectError } from '@connectrpc/connect';
|
||||
import { RotateCcw } from '@lucide/svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import CopyInput from '../ui/copy-input/copy-input.svelte';
|
||||
import Separator from '../ui/separator/separator.svelte';
|
||||
|
||||
interface Props {
|
||||
item: Profile;
|
||||
@@ -75,8 +75,10 @@
|
||||
description: item.description,
|
||||
regenerateToken: true
|
||||
});
|
||||
if (!response.profile) throw new Error('Failed to regenerate token');
|
||||
toast.success(`Token regenerated successfully`);
|
||||
if (response.profile) profileStore.value = response.profile;
|
||||
item = response.profile;
|
||||
profileStore.value = response.profile;
|
||||
} catch (err) {
|
||||
const e = ConnectError.from(err);
|
||||
toast.error('Failed to regenerate token', { description: e.message });
|
||||
|
||||
Reference in New Issue
Block a user