diff --git a/cmd/policy/policy_test.go b/cmd/policy/policy_test.go index 8fbe1a72c..227a6a66d 100644 --- a/cmd/policy/policy_test.go +++ b/cmd/policy/policy_test.go @@ -635,7 +635,10 @@ test: config CompilerServerHandler: func(w http.ResponseWriter, r *http.Request) { var req config.CompileConfigRequest err := json.NewDecoder(r.Body).Decode(&req) - require.NoError(t, err) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } // dummy compilation here (remove the _compiled_ key in compiled config, as compiled config can't have that at top-level key). var yamlResp map[string]any @@ -678,7 +681,10 @@ test: config CompilerServerHandler: func(w http.ResponseWriter, r *http.Request) { var req config.CompileConfigRequest err := json.NewDecoder(r.Body).Decode(&req) - require.NoError(t, err) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } response := config.ConfigResponse{Valid: true, SourceYaml: req.ConfigYaml, OutputYaml: req.ConfigYaml} @@ -837,7 +843,10 @@ test: config CompilerServerHandler: func(w http.ResponseWriter, r *http.Request) { var req config.CompileConfigRequest err := json.NewDecoder(r.Body).Decode(&req) - require.NoError(t, err) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } response := config.ConfigResponse{Valid: true, SourceYaml: req.ConfigYaml, OutputYaml: req.ConfigYaml} @@ -1082,7 +1091,10 @@ test: config CompilerServerHandler: func(w http.ResponseWriter, r *http.Request) { var req config.CompileConfigRequest err := json.NewDecoder(r.Body).Decode(&req) - require.NoError(t, err) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + return + } response := config.ConfigResponse{Valid: true, SourceYaml: req.ConfigYaml, OutputYaml: req.ConfigYaml} diff --git a/config/api_client.go b/config/api_client.go index cd87a6fd6..6c62bef0b 100644 --- a/config/api_client.go +++ b/config/api_client.go @@ -3,7 +3,6 @@ package config import ( "fmt" "net/url" - "sync" "github.com/CircleCI-Public/circleci-cli/api/graphql" "github.com/CircleCI-Public/circleci-cli/api/rest" @@ -11,10 +10,6 @@ import ( ) var ( - compiler APIClient - compilerError error - once sync.Once - compilePath = "compile-config-with-defaults" ) @@ -24,15 +19,6 @@ type APIClient interface { CompileConfig(configContent string, orgID string, params Parameters, values Values) (*ConfigResponse, error) } -func GetAPIClient(config *settings.Config) (APIClient, error) { - if compiler == nil { - once.Do(func() { - compiler, compilerError = newAPIClient(config) - }) - } - return compiler, compilerError -} - func newAPIClient(config *settings.Config) (APIClient, error) { hostValue := GetCompileHost(config.Host) restClient := rest.NewFromConfig(hostValue, config) diff --git a/config/config.go b/config/config.go index 741384220..9d52be9a1 100644 --- a/config/config.go +++ b/config/config.go @@ -24,7 +24,7 @@ type ConfigCompiler struct { } func NewWithConfig(cfg *settings.Config) (*ConfigCompiler, error) { - apiClient, err := GetAPIClient(cfg) + apiClient, err := newAPIClient(cfg) if err != nil { return nil, err } diff --git a/config/v2_api_client.go b/config/v2_api_client.go index 6d9c6bbe1..2ae9a3152 100644 --- a/config/v2_api_client.go +++ b/config/v2_api_client.go @@ -34,9 +34,7 @@ func (client *v2APIClient) CompileConfig(configContent string, orgID string, par req, err := client.restClient.NewRequest( "POST", - &url.URL{ - Path: "compile-config-with-defaults", - }, + &url.URL{Path: compilePath}, compileRequest, ) if err != nil {