Files
vHost/backend/internal/service/phpmyadmin.go
T

44 lines
1.4 KiB
Go

package service
import (
"context"
"errors"
"fmt"
"sea-vhost/internal/isolation"
"sea-vhost/internal/scope"
"sea-vhost/internal/store"
)
func (s *Projects) PHPMyAdmin(ctx context.Context, u store.User, id uint64, q isolation.PHPMyAdminRequest) (isolation.PHPMyAdminResponse, error) {
p, e := s.authorizedProject(ctx, u, id)
if e != nil {
return isolation.PHPMyAdminResponse{}, e
}
ctx = scope.WithProject(ctx, p.ID, p.NodeID)
if q.Method == "POST" {
if e = s.ensureTenantWritable(ctx, p.TenantID); e != nil {
return isolation.PHPMyAdminResponse{}, e
}
}
stored, e := s.store.Credentials(ctx, p.TenantID, p.ID)
if e != nil {
return isolation.PHPMyAdminResponse{}, e
}
password, e := s.credentials.Open(credentialLabel("database", p.ID), stored.DatabasePasswordCipher)
if e != nil {
return isolation.PHPMyAdminResponse{}, errors.New("无法解密数据库凭据")
}
plan, _, e := s.store.PlanAndUsage(ctx, p.TenantID)
if e != nil {
return isolation.PHPMyAdminResponse{}, e
}
q.Project = isolation.ProjectSpec{TenantID: p.TenantID, HostName: p.HostName, RunPath: p.RunPath, StorageBytes: plan.StorageBytes, ProcessLimit: uint32(p.ProcessLimit)}
q.Username = stored.DatabaseUsername
q.Password = password
proxy, ok := s.isolation.(isolation.PHPMyAdminProxy)
if !ok {
return isolation.PHPMyAdminResponse{}, fmt.Errorf("节点未支持 phpMyAdmin")
}
return proxy.PHPMyAdmin(ctx, q)
}