反馈server工作区的创建情况
(feedbackCommand FeedbackCommandEnum, cmd *cobra.Command, isSuccess bool, webidePort *int, workspaceInfo workspace.WorkspaceInfo, message string, containerId string)
| 86 | |
| 87 | // 反馈server工作区的创建情况 |
| 88 | func Feedback_Finish(feedbackCommand FeedbackCommandEnum, cmd *cobra.Command, |
| 89 | isSuccess bool, webidePort *int, workspaceInfo workspace.WorkspaceInfo, message string, containerId string) error { |
| 90 | if workspaceInfo.CliRunningEnv != workspace.CliRunningEvnEnum_Server { |
| 91 | return errors.New("当前仅支持在 mode=server 的模式下运行!") |
| 92 | } |
| 93 | |
| 94 | // 验证参数是否有值 |
| 95 | //Check(cmd) |
| 96 | |
| 97 | //1. 从参数中获取相应值 |
| 98 | serverModeInfo, err := GetServerModeInfo(cmd) |
| 99 | //1.1. validate |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | if serverModeInfo.ServerHost == "" { |
| 104 | return errors.New("ServerHost is nil") |
| 105 | } |
| 106 | //1.2. |
| 107 | serverFeedbackUrl, _ := common.UrlJoin(serverModeInfo.ServerHost, "/api/smartide/workspace/finish") |
| 108 | configFileContent, _ := workspaceInfo.ConfigYaml.ToYaml() |
| 109 | tempYamlContent, _ := workspaceInfo.TempDockerCompose.ToYaml() |
| 110 | linkYmalContent, _ := workspaceInfo.ConfigYaml.Workspace.LinkCompose.ToYaml() |
| 111 | if workspaceInfo.Mode == workspace.WorkingMode_K8s { |
| 112 | tempYamlContent, _ = workspaceInfo.K8sInfo.TempK8sConfig.ConvertToK8sYaml() |
| 113 | linkYmalContent, _ = workspaceInfo.K8sInfo.OriginK8sYaml.ConvertToK8sYaml() |
| 114 | } |
| 115 | //1.3. workspace id |
| 116 | worksspaceId := strconv.Itoa(int(workspaceInfo.ServerWorkSpace.ID)) |
| 117 | if worksspaceId == "" { |
| 118 | worksspaceId = serverModeInfo.ServerWorkspaceid |
| 119 | } |
| 120 | if worksspaceId == "" { |
| 121 | return errors.New("workspace id is nil") |
| 122 | } else if strings.Contains(strings.ToLower(worksspaceId), "WS") { |
| 123 | flysnowRegexp := regexp.MustCompile(`[1-9]{1}[0-9].*`) |
| 124 | params := flysnowRegexp.FindStringSubmatch(worksspaceId) |
| 125 | worksspaceId = params[0] |
| 126 | } |
| 127 | //1.4. extend |
| 128 | extend := workspaceInfo.Extend.ToJson() |
| 129 | |
| 130 | //2. |
| 131 | datas := map[string]interface{}{ |
| 132 | "command": string(feedbackCommand), |
| 133 | "serverWorkspaceid": worksspaceId, |
| 134 | "serverUserName": serverModeInfo.ServerUsername, |
| 135 | "isSuccess": isSuccess, |
| 136 | "message": message, |
| 137 | "containerId": containerId, |
| 138 | } |
| 139 | if feedbackCommand == FeedbackCommandEnum_Start { // 只有start的时候,才需要传递文件内容 |
| 140 | datas["configFileContent"] = configFileContent |
| 141 | datas["tempDockerComposeContent"] = tempYamlContent |
| 142 | datas["linkDockerCompose"] = linkYmalContent |
| 143 | datas["extend"] = extend |
| 144 | } else if feedbackCommand == FeedbackCommandEnum_Ingress || feedbackCommand == FeedbackCommandEnum_ApplySSH { |
| 145 | datas["extend"] = extend |
nothing calls this directly
no test coverage detected