Skip to content

Commit

Permalink
refactor: remove task id config
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki0 committed Apr 18, 2023
1 parent fb84471 commit e2c4d2b
Show file tree
Hide file tree
Showing 16 changed files with 3 additions and 652 deletions.
6 changes: 0 additions & 6 deletions api/api_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 22,6 @@ const (
ErrServerFail // api: server fail
ErrGeneralError // api: general error
ErrValidateFail // api: validation fail
ErrTaskNotFound // api: task not found
ErrTaskNotCli // api: task not for CLI
)

func (i apiError) Error() string {
Expand Down Expand Up @@ -76,10 74,6 @@ func (i *Error) Is(target error) bool {
case ErrTimeout:
r, ok := i.Cause.(*url.Error)
return ok && r.Timeout()
case ErrTaskNotFound:
return i.Code == 30033
case ErrTaskNotCli:
return i.Code == 30046
}
if r, ok := target.(*Error); ok {
if i.Code == r.Code {
Expand Down
6 changes: 2 additions & 4 deletions api/apierror_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/create_sub_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 16,6 @@ type CreateSubTaskRequest struct {
Message *string `json:"message,omitempty"` // 提交信息
PushTime *time.Time `json:"push_time,omitempty"` // 提交时间
SubtaskName string `json:"subtask_name"`
TaskID *string `json:"task_id,omitempty"`
Dir string `json:"dir"` // 路径
CliVersion string `json:"cli_version"`
}
Expand Down
13 changes: 0 additions & 13 deletions cmd/murphy/internal/cv/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 40,6 @@ func DisplayTLSNotice(ctx context.Context) {
ui.Use(ctx).Display(ui.MsgWarn, "当前建立的网络连接不安全,通讯已断开,您可以通过 -x 或 --allow-insecure 选项忽略这个错误")
}

func DisplayTaskNotForCli(ctx context.Context) {
ui.Use(ctx).Display(ui.MsgError, "扫描失败,该任务不是CLI检测方式,无法检测")
}

func DisplayCreateSubtaskErr(ctx context.Context, e error) {
ui.Use(ctx).Display(ui.MsgError, "扫描失败:" e.Error())
}
Expand Down Expand Up @@ -94,18 90,9 @@ func DisplayUploadErr(ctx context.Context, e error) {
ui.Use(ctx).Display(ui.MsgError, "上传失败:" e.Error())
}

func DisplayBadTaskId(ctx context.Context) {
ui.Use(ctx).Display(ui.MsgError, "无效的任务 ID")
}

func DisplayAlertMessage(ctx context.Context, msg string) {
if msg == "" {
return
}
ui.Use(ctx).Display(ui.MsgNotice, msg)
}

func DisplayUseDefaultTaskId(ctx context.Context) {
ui.Use(ctx).Display(ui.MsgNotice, "未指定 --task-id,检测结果将会关联至“CLI默认项目”中")
ui.Use(ctx).Display(ui.MsgNotice, "请参考文档 https://www.murphysec.com/docs/guides/faqs/cli-taskid.html")
}
2 changes: 0 additions & 2 deletions cmd/murphy/internal/internalcmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 5,6 @@ import "github.com/spf13/cobra"
func Cmd() *cobra.Command {
var c = &cobra.Command{Use: "internal", Hidden: true}
c.AddCommand(cppFileHashCmd())
c.AddCommand(internalWriteTaskIdCmd())
c.AddCommand(internalReadTaskIdCmd())
c.AddCommand(machineidCmd())
c.AddCommand(scannerScanCmd())
return c
Expand Down
38 changes: 0 additions & 38 deletions cmd/murphy/internal/internalcmd/read_task_id.go

This file was deleted.

35 changes: 0 additions & 35 deletions cmd/murphy/internal/internalcmd/write_task_id.go

This file was deleted.

43 changes: 0 additions & 43 deletions cmd/murphy/internal/scan/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,6 @@ import (
"github.com/murphysecurity/murphysec/api"
"github.com/murphysecurity/murphysec/cmd/murphy/internal/common"
"github.com/murphysecurity/murphysec/cmd/murphy/internal/cv"
"github.com/murphysecurity/murphysec/config"
"github.com/murphysecurity/murphysec/infra/exitcode"
"github.com/murphysecurity/murphysec/infra/logctx"
"github.com/murphysecurity/murphysec/infra/ui"
Expand All @@ -19,7 18,6 @@ import (
"path/filepath"
)

var cliTaskIdOverride string
var jsonOutput bool

func Cmd() *cobra.Command {
Expand All @@ -28,7 26,6 @@ func Cmd() *cobra.Command {
c.Short = "scan project directory"
c.Args = cobra.ExactArgs(1)
c.Run = scanRun
c.Flags().StringVar(&cliTaskIdOverride, "task-id", "", "specify task id, and write it to config")
c.Flags().BoolVar(&jsonOutput, "json", false, "")
return &c
}
Expand Down Expand Up @@ -73,23 70,6 @@ func scanRun(cmd *cobra.Command, args []string) {
return
}

if cliTaskIdOverride != "" {
logger.Infof("CLI task id override: %s", cliTaskIdOverride)
cf := config.RepoConfig{TaskId: cliTaskIdOverride}
if e := cf.Validate(); e != nil {
cv.DisplayBadTaskId(ctx)
logger.Error(e)
exitcode.Set(1)
return
}
e = config.WriteRepoConfig(ctx, scanDir, model.AccessTypeCli, config.RepoConfig{TaskId: cliTaskIdOverride})
if e != nil {
cv.DisplayInitializeFailed(ctx, e)
logger.Error(e)
exitcode.Set(1)
return
}
}
_, e = scan(ctx, scanDir, model.AccessTypeCli)
if e != nil {
logger.Error(e)
Expand All @@ -106,7 86,6 @@ func IdeaScan() *cobra.Command {
c.Hidden = true
c.Flags().String("ide", "", "unused")
must.M(c.Flags().MarkHidden("ide"))
c.Flags().StringVar(&cliTaskIdOverride, "task-id", "", "specify task id, and write it to config")
return &c
}

Expand Down Expand Up @@ -152,24 131,6 @@ func ideascanRun(cmd *cobra.Command, args []string) {
return
}

if cliTaskIdOverride != "" {
logger.Infof("CLI task id override: %s", cliTaskIdOverride)
cf := config.RepoConfig{TaskId: cliTaskIdOverride}
if e := cf.Validate(); e != nil {
cv.DisplayBadTaskId(ctx)
logger.Error(e)
exitcode.Set(1)
return
}
e = config.WriteRepoConfig(ctx, scanDir, accessType, config.RepoConfig{TaskId: cliTaskIdOverride})
if e != nil {
cv.DisplayInitializeFailed(ctx, e)
logger.Error(e)
exitcode.Set(1)
return
}
}

task, e := scan(ctx, scanDir, accessType)
if e != nil {
autoReportIde(e)
Expand All @@ -186,10 147,6 @@ type ideErrorResp struct {
}

func autoReportIde(e error) {
if errors.Is(e, api.ErrTaskNotFound) {
reportIdeError(model.IDEStatusTaskNotExists, e)
return
}
if errors.Is(e, api.ErrTokenInvalid) {
reportIdeError(model.IDEStatusTokenInvalid, e)
return
Expand Down
29 changes: 0 additions & 29 deletions cmd/murphy/internal/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,6 @@ import (
"errors"
"github.com/murphysecurity/murphysec/api"
"github.com/murphysecurity/murphysec/cmd/murphy/internal/cv"
"github.com/murphysecurity/murphysec/config"
"github.com/murphysecurity/murphysec/gitinfo"
"github.com/murphysecurity/murphysec/infra/logctx"
"github.com/murphysecurity/murphysec/infra/ref"
Expand Down Expand Up @@ -34,22 33,6 @@ func scan(ctx context.Context, dir string, accessType model.AccessType) (*model.
createSubtask.ScanMode = model.ScanModeSource
createSubtask.Dir = dir

// get repo config
var shouldWriteConfig = false
var repoConfig *config.RepoConfig
repoConfig, e = config.ReadRepoConfig(ctx, dir, accessType)
if e == nil {
createSubtask.TaskID = ref.OmitZero(repoConfig.TaskId)
if repoConfig.TaskId == "" {
logger.Infof("task id not set, will be written soom")
shouldWriteConfig = true
}
}
if errors.Is(e, config.ErrRepoConfigNotFound) {
logger.Infof("config not found, will be written soon")
shouldWriteConfig = true
}

// get git info
var gitSummary *gitinfo.Summary
gitSummary, e = gitinfo.GetSummary(ctx, dir)
Expand All @@ -71,25 54,13 @@ func scan(ctx context.Context, dir string, accessType model.AccessType) (*model.
cv.DisplayTLSNotice(ctx)
return nil, e
}
if errors.Is(e, api.ErrTaskNotCli) {
cv.DisplayTaskNotForCli(ctx)
return nil, e
}
if e != nil {
cv.DisplayCreateSubtaskErr(ctx, e)
return nil, e
}
logger.Infof("subtask created, %s / %s", createTaskResp.TaskID, createTaskResp.SubtaskID)
cv.DisplayAlertMessage(ctx, createTaskResp.AlertMessage)
cv.DisplaySubtaskCreated(ctx, createTaskResp.ProjectsName, createTaskResp.TaskName, createTaskResp.TaskID, createSubtask.SubtaskName, createTaskResp.SubtaskID)
if shouldWriteConfig {
cv.DisplayUseDefaultTaskId(ctx)
logger.Infof("creating repo config...")
e = config.WriteRepoConfig(ctx, dir, accessType, config.RepoConfig{TaskId: createTaskResp.TaskID})
if e != nil {
logger.Warnf("repo config: %v", e)
}
}

// create task object
task := &model.ScanTask{
Expand Down
Loading

0 comments on commit e2c4d2b

Please sign in to comment.