diff --git a/hrp/internal/builtin/utils.go b/hrp/internal/builtin/utils.go index ad0c5297..d53c81f1 100644 --- a/hrp/internal/builtin/utils.go +++ b/hrp/internal/builtin/utils.go @@ -29,7 +29,6 @@ import ( "gopkg.in/yaml.v3" "github.com/httprunner/httprunner/v4/hrp/code" - "github.com/httprunner/httprunner/v4/hrp/internal/env" "github.com/httprunner/httprunner/v4/hrp/internal/json" ) @@ -456,13 +455,14 @@ func DownloadFile(filePath string, fileUrl string) error { return err } - if env.EAPI_TOKEN != "" { + eapiToken := os.Getenv("EAPI_TOKEN") + if eapiToken != "" { if parsedURL.Host != "gtf-eapi-cn.bytedance.com" && parsedURL.Host != "gtf-eapi-cn.bytedance.net" { return errors.New("invalid domain: must be gtf-eapi-cn.bytedance.com") } // 添加自定义头部 req.Header.Add("accessKey", "ies.vedem.video") - req.Header.Add("token", env.EAPI_TOKEN) + req.Header.Add("token", eapiToken) } // 创建一个 HTTP 客户端并发送请求 diff --git a/hrp/internal/env/env.go b/hrp/internal/env/env.go index 2e053e82..da2e4a77 100644 --- a/hrp/internal/env/env.go +++ b/hrp/internal/env/env.go @@ -6,20 +6,6 @@ import ( "time" ) -var ( - WDA_USB_DRIVER = os.Getenv("WDA_USB_DRIVER") - WDA_LOCAL_PORT = os.Getenv("WDA_LOCAL_PORT") - WDA_LOCAL_MJPEG_PORT = os.Getenv("WDA_LOCAL_MJPEG_PORT") - VEDEM_IMAGE_URL = os.Getenv("VEDEM_IMAGE_URL") - VEDEM_IMAGE_AK = os.Getenv("VEDEM_IMAGE_AK") - VEDEM_IMAGE_SK = os.Getenv("VEDEM_IMAGE_SK") - EAPI_TOKEN = os.Getenv("EAPI_TOKEN") - DISABLE_GA = os.Getenv("DISABLE_GA") - DISABLE_SENTRY = os.Getenv("DISABLE_SENTRY") - PYPI_INDEX_URL = os.Getenv("PYPI_INDEX_URL") - PATH = os.Getenv("PATH") -) - const ( ResultsDirName = "results" ScreenshotsDirName = "screenshots" diff --git a/hrp/internal/sdk/ga4.go b/hrp/internal/sdk/ga4.go index 5a736476..27c4262d 100644 --- a/hrp/internal/sdk/ga4.go +++ b/hrp/internal/sdk/ga4.go @@ -8,6 +8,7 @@ import ( "math/rand" "net/http" "net/url" + "os" "runtime" "time" @@ -16,7 +17,6 @@ import ( "github.com/rs/zerolog/log" uuid "github.com/satori/go.uuid" - "github.com/httprunner/httprunner/v4/hrp/internal/env" "github.com/httprunner/httprunner/v4/hrp/internal/version" ) @@ -195,7 +195,7 @@ func (g *GA4Client) SendEvent(event Event) error { } func SendGA4Event(name string, params map[string]interface{}) { - if env.DISABLE_GA == "true" { + if os.Getenv("DISABLE_GA") == "true" { // do not send GA4 events in CI environment return } diff --git a/hrp/internal/sdk/sentry.go b/hrp/internal/sdk/sentry.go index ba30dbf9..5f3eb7c7 100644 --- a/hrp/internal/sdk/sentry.go +++ b/hrp/internal/sdk/sentry.go @@ -2,11 +2,11 @@ package sdk import ( "fmt" + "os" "github.com/getsentry/sentry-go" "github.com/rs/zerolog/log" - "github.com/httprunner/httprunner/v4/hrp/internal/env" "github.com/httprunner/httprunner/v4/hrp/internal/version" ) @@ -16,7 +16,7 @@ const ( func init() { // init sentry sdk - if env.DISABLE_SENTRY == "true" { + if os.Getenv("DISABLE_SENTRY") == "true" { return } err := sentry.Init(sentry.ClientOptions{ diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index 5ff48090..cdc2217c 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v5.0.0-beta-2410112229 +v5.0.0-beta-2410161532 diff --git a/hrp/pkg/uixt/ai_vedem.go b/hrp/pkg/uixt/ai_vedem.go index 00118c35..bb84847d 100644 --- a/hrp/pkg/uixt/ai_vedem.go +++ b/hrp/pkg/uixt/ai_vedem.go @@ -6,6 +6,7 @@ import ( "io" "mime/multipart" "net/http" + "os" "time" "github.com/pkg/errors" @@ -13,7 +14,6 @@ import ( "github.com/httprunner/httprunner/v4/hrp/code" "github.com/httprunner/httprunner/v4/hrp/internal/builtin" - "github.com/httprunner/httprunner/v4/hrp/internal/env" "github.com/httprunner/httprunner/v4/hrp/internal/json" ) @@ -105,7 +105,7 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer, options ...ActionOp continue } - req, err = http.NewRequest("POST", env.VEDEM_IMAGE_URL, copiedBodyBuf) + req, err = http.NewRequest("POST", os.Getenv("VEDEM_IMAGE_URL"), copiedBodyBuf) if err != nil { err = errors.Wrap(code.CVRequestError, fmt.Sprintf("construct request error: %v", err)) @@ -117,7 +117,7 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer, options ...ActionOp // req.Header.Add("x-use-ppe", "1") signToken := "UNSIGNED-PAYLOAD" - token := builtin.Sign("auth-v2", env.VEDEM_IMAGE_AK, env.VEDEM_IMAGE_SK, []byte(signToken)) + token := builtin.Sign("auth-v2", os.Getenv("VEDEM_IMAGE_AK"), os.Getenv("VEDEM_IMAGE_SK"), []byte(signToken)) req.Header.Add("Agw-Auth", token) req.Header.Add("Agw-Auth-Content", signToken) @@ -197,14 +197,15 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer, options ...ActionOp } func checkEnv() error { - if env.VEDEM_IMAGE_URL == "" { + vedemImageURL := os.Getenv("VEDEM_IMAGE_URL") + if vedemImageURL == "" { return errors.Wrap(code.CVEnvMissedError, "VEDEM_IMAGE_URL missed") } - log.Info().Str("VEDEM_IMAGE_URL", env.VEDEM_IMAGE_URL).Msg("get env") - if env.VEDEM_IMAGE_AK == "" { + log.Info().Str("VEDEM_IMAGE_URL", vedemImageURL).Msg("get env") + if os.Getenv("VEDEM_IMAGE_AK") == "" { return errors.Wrap(code.CVEnvMissedError, "VEDEM_IMAGE_AK missed") } - if env.VEDEM_IMAGE_SK == "" { + if os.Getenv("VEDEM_IMAGE_SK") == "" { return errors.Wrap(code.CVEnvMissedError, "VEDEM_IMAGE_SK missed") } return nil diff --git a/hrp/pkg/uixt/ios_device.go b/hrp/pkg/uixt/ios_device.go index 5e144faa..b5993e25 100644 --- a/hrp/pkg/uixt/ios_device.go +++ b/hrp/pkg/uixt/ios_device.go @@ -322,7 +322,7 @@ func (dev *IOSDevice) NewDriver(options ...DriverOption) (driverExt *DriverExt, } var driver IWebDriver - if env.WDA_USB_DRIVER == "" { + if os.Getenv("WDA_USB_DRIVER") == "" { // default use http driver driver, err = dev.NewHTTPDriver(capabilities) } else { @@ -611,7 +611,7 @@ func (dev *IOSDevice) pcapOpitons() (pcapOptions []gidevice.PcapOption) { // NewHTTPDriver creates new remote HTTP client, this will also start a new session. func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDriver, err error) { var localPort int - localPort, err = strconv.Atoi(env.WDA_LOCAL_PORT) + localPort, err = strconv.Atoi(os.Getenv("WDA_LOCAL_PORT")) if err != nil { localPort, err = builtin.GetFreePort() if err != nil { @@ -628,7 +628,7 @@ func (dev *IOSDevice) NewHTTPDriver(capabilities Capabilities) (driver IWebDrive } var localMjpegPort int - localMjpegPort, err = strconv.Atoi(env.WDA_LOCAL_MJPEG_PORT) + localMjpegPort, err = strconv.Atoi(os.Getenv("WDA_LOCAL_MJPEG_PORT")) if err != nil { localMjpegPort, err = builtin.GetFreePort() if err != nil {