反馈server工作区的创建情况
(feedbackCommand FeedbackCommandEnum, workspaceStatus response.WorkspaceStatusEnum, cmd *cobra.Command, workspaceInfo workspace.WorkspaceInfo, message string)
| 157 | |
| 158 | // 反馈server工作区的创建情况 |
| 159 | func Feedback_Pending(feedbackCommand FeedbackCommandEnum, workspaceStatus response.WorkspaceStatusEnum, |
| 160 | cmd *cobra.Command, |
| 161 | workspaceInfo workspace.WorkspaceInfo, message string) error { |
| 162 | if workspaceInfo.CliRunningEnv != workspace.CliRunningEvnEnum_Server { |
| 163 | return errors.New("当前仅支持在 mode=server 的模式下运行!") |
| 164 | } |
| 165 | |
| 166 | //1. 从参数中获取相应值 |
| 167 | serverModeInfo, err := GetServerModeInfo(cmd) |
| 168 | //1.1. validate |
| 169 | if err != nil { |
| 170 | return err |
| 171 | } |
| 172 | if serverModeInfo.ServerHost == "" { |
| 173 | return errors.New("ServerHost is nil") |
| 174 | } |
| 175 | //1.2. |
| 176 | serverFeedbackUrl, _ := common.UrlJoin(serverModeInfo.ServerHost, "/api/smartide/workspace/pending") |
| 177 | |
| 178 | //1.3. workspace id |
| 179 | worksspaceId := strconv.Itoa(int(workspaceInfo.ServerWorkSpace.ID)) |
| 180 | if worksspaceId == "" { |
| 181 | worksspaceId = serverModeInfo.ServerWorkspaceid |
| 182 | } |
| 183 | if worksspaceId == "" { |
| 184 | return errors.New("workspace id is nil") |
| 185 | } else if strings.Contains(strings.ToLower(worksspaceId), "WS") { |
| 186 | flysnowRegexp := regexp.MustCompile(`[1-9]{1}[0-9].*`) |
| 187 | params := flysnowRegexp.FindStringSubmatch(worksspaceId) |
| 188 | worksspaceId = params[0] |
| 189 | } |
| 190 | |
| 191 | //2. |
| 192 | datas := map[string]interface{}{ |
| 193 | "command": string(feedbackCommand), |
| 194 | "serverWorkspaceid": worksspaceId, |
| 195 | "serverUserName": serverModeInfo.ServerUsername, |
| 196 | "message": message, |
| 197 | } |
| 198 | if feedbackCommand == FeedbackCommandEnum_Start && workspaceInfo.Mode == workspace.WorkingMode_K8s { // 只有start的时候,才需要传递文件内容 |
| 199 | datas["kubeNamespace"] = workspaceInfo.K8sInfo.Namespace |
| 200 | datas["status"] = workspaceStatus |
| 201 | } |
| 202 | headers := map[string]string{"Content-Type": "application/json", "x-token": serverModeInfo.ServerToken} |
| 203 | |
| 204 | httpClient := common.CreateHttpClient(6, 30*time.Second, 3*time.Second, common.ResponseBodyTypeEnum_JSON) |
| 205 | _, err = httpClient.PostJson(serverFeedbackUrl.String(), datas, headers) // post 请求 |
| 206 | |
| 207 | if err != nil { |
| 208 | return err |
| 209 | } |
| 210 | |
| 211 | return nil |
| 212 | } |
| 213 | |
| 214 | // 反馈server工作区的创建情况 |
| 215 | func Send_WorkspaceInfo(callbackAPI string, feedbackCommand FeedbackCommandEnum, cmd *cobra.Command, |
nothing calls this directly
no test coverage detected