startoplogic.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package logic
  2. import (
  3. "context"
  4. "net/http"
  5. "strings"
  6. "dag-jupyter/internal/api"
  7. "dag-jupyter/internal/svc"
  8. "dag-jupyter/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type StartOpLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewStartOpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartOpLogic {
  17. return &StartOpLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. }
  22. }
  23. func formatPassword(password string) string {
  24. password = strings.ReplaceAll(password, "$", `\$`)
  25. password = strings.ReplaceAll(password, ",", `\,`)
  26. return password
  27. }
  28. // helm upgrade --install aihub-dag-jpt-1 ./chart -f chart/values.yaml -n airflow \
  29. // --set "ingress.jupyterlab.hosts[0].host=jupyterlab.sxkj.com,ingress.jupyterlab.hosts[0].paths[0].path=/nbsss" \
  30. // --set jupyterlab.image.repository=SXKJ:32775/jupyterlab \
  31. // --set jupyterlab.image.tag=dev
  32. // --set jupyterlab.config.password="\"argon2:\$argon2id\$v=19\$m=10240\,t=10\,p=8\$vSn0+TR0clV8kla6yqcZqQ\$XgjDauBkBL5aY8C8668HKJjoTX7BUT/WccJ+BeANHq4\"" \
  33. // --set jupyterlab.config.baseUrl="/nbsss" \
  34. // --set jupyterlab.config.workspace="hello2" \
  35. // --kubeconfig=`pwd`/config-sxkj.yaml
  36. func (l *StartOpLogic) StartOp(req *types.CreateJupyterInfo) (resp *types.Response, err error) {
  37. req.Password = formatPassword(req.Password)
  38. logx.Infof("req: %+v", req)
  39. err = api.Install(req)
  40. data := map[string]interface{}{
  41. "namespace": req.Namespace,
  42. "release_name": req.ReleaseName,
  43. "base_url": req.BaseUrl,
  44. "image": req.Image,
  45. "host": req.Host,
  46. "tag": req.Tag,
  47. "path": req.Path,
  48. "workspace": req.Workspace,
  49. }
  50. if err != nil {
  51. return &types.Response{
  52. Data: err.Error(),
  53. Code: http.StatusBadRequest,
  54. }, nil
  55. }
  56. return &types.Response{
  57. Data: data,
  58. Code: http.StatusOK,
  59. }, nil
  60. }