Skip to content

Commit

Permalink
refactor: split constants to env package
Browse files Browse the repository at this point in the history
  • Loading branch information
iseki0 committed Jun 3, 2024
1 parent d3a8185 commit e1c94c2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/murphy/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func preRun(cmd *cobra.Command, args []string) error {

func rootCmd() *cobra.Command {
c := &cobra.Command{
Use: "murphysec",
Use: env.RootCommand,
PersistentPreRunE: preRun,
TraverseChildren: true,
Run: func(cmd *cobra.Command, args []string) {
Expand Down
3 changes: 2 additions & 1 deletion config/tokenfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"context"
"github.com/mitchellh/go-homedir"
"github.com/murphysecurity/murphysec/env"
"github.com/murphysecurity/murphysec/infra/logctx"
"github.com/murphysecurity/murphysec/utils"
"io"
Expand All @@ -13,7 +14,7 @@ import (
)

const (
DefaultTokenFile = "~/.murphysec/token"
DefaultTokenFile = "~/" + env.HomeSubdir + "/token"
TokenFileMaxSize = 1 * 1024
)

Expand Down
2 changes: 0 additions & 2 deletions env/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ func envi(name string, defaultValue int) int {
}
}

const DefaultServerURL = "https://www.murphysec.com"

var ServerURLOverride = os.Getenv("MPS_CLI_SERVER")
var APITokenOverride = os.Getenv("API_TOKEN")
var ScannerScan = false
Expand Down
7 changes: 7 additions & 0 deletions env/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package env

const RootCommand = "murphysec"
const UserAgentPrefix = "murphy-cli"
const SpdxName = "com.github.murphysecurity/murphysec"
const HomeSubdir = ".murphysec"
const DefaultServerURL = "https://www.murphysec.com"
3 changes: 2 additions & 1 deletion inspector/textual_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package inspector
import (
"encoding/json"
"fmt"
"github.com/murphysecurity/murphysec/env"
"github.com/murphysecurity/murphysec/model"
"time"
)
Expand Down Expand Up @@ -103,7 +104,7 @@ func BuildSpdx(task *model.ScanTask) []byte {
"created": time.Now(),
"creators": []string{"Tool: murphysec-cli"},
},
"name": "com.github.murphysecurity/murphysec",
"name": env.SpdxName,
"dataLicense": "CC0-1.0",
"packages": packages,
"relationships": relationships,
Expand Down
3 changes: 2 additions & 1 deletion logger/log_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logger
import (
"fmt"
"github.com/mitchellh/go-homedir"
"github.com/murphysecurity/murphysec/env"
"github.com/murphysecurity/murphysec/errors"
"github.com/murphysecurity/murphysec/utils/must"
"os"
Expand All @@ -12,7 +13,7 @@ import (
"time"
)

const defaultLogFilePath = ".murphysec/logs"
const defaultLogFilePath = env.HomeSubdir + "/logs"

// CreateLogFile create log file. If _filepath is empty, use default log path
func CreateLogFile(_filepath string) (_ *os.File, err error) {
Expand Down
3 changes: 2 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package version

import (
"github.com/iseki0/osname"
"github.com/murphysecurity/murphysec/env"
"github.com/murphysecurity/murphysec/infra/buildinfo"
"runtime"
"strings"
)

const name = "murphysec-cli"
const name = env.UserAgentPrefix

var userAgent string

Expand Down

0 comments on commit e1c94c2

Please sign in to comment.