Skip to content

Commit

Permalink
Establish cloud host as cloud.rwx.com (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywok authored Dec 7, 2023
1 parent 715fe00 commit 77f249b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 95 deletions.
2 changes: 1 addition & 1 deletion cmd/mint/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func init() {
// A different host can only be set over the environment
mintHost = os.Getenv("MINT_HOST")
if mintHost == "" {
mintHost = "mint.rwx.com"
mintHost = "cloud.rwx.com"
}

runCmd.Flags().BoolVar(&NoCache, "no-cache", false, "do not read or write to the cache")
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = Describe("CLI Service", func() {
receivedFileContent = cfg.TaskDefinitions[0].FileContents
return &client.InitiateRunResult{
RunId: "785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://mint.rwx.com/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://cloud.rwx.com/mint/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
TargetedTaskKeys: []string{},
DefinitionPath: ".mint/mint.yml",
}, nil
Expand All @@ -92,7 +92,7 @@ var _ = Describe("CLI Service", func() {
receivedFileContent = cfg.TaskDefinitions[0].FileContents
return &client.InitiateRunResult{
RunId: "785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://mint.rwx.com/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://cloud.rwx.com/mint/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
TargetedTaskKeys: []string{},
DefinitionPath: ".mint/mint.yml",
}, nil
Expand All @@ -113,7 +113,7 @@ var _ = Describe("CLI Service", func() {
receivedFileContent = cfg.TaskDefinitions[0].FileContents
return &client.InitiateRunResult{
RunId: "785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://mint.rwx.com/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://cloud.rwx.com/mint/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
TargetedTaskKeys: []string{},
DefinitionPath: ".mint/mint.yml",
}, nil
Expand Down Expand Up @@ -193,7 +193,7 @@ var _ = Describe("CLI Service", func() {
}
return &client.InitiateRunResult{
RunId: "785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://mint.rwx.com/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
RunURL: "https://cloud.rwx.com/mint/rwx/runs/785ce4e8-17b9-4c8b-8869-a55e95adffe7",
TargetedTaskKeys: []string{},
DefinitionPath: ".mint/mint.yml",
}, nil
Expand Down
14 changes: 2 additions & 12 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"net/http"
"strings"

"github.com/pkg/errors"

Expand All @@ -16,7 +15,6 @@ import (
// Client is an API Client for Mint
type Client struct {
RoundTrip func(*http.Request) (*http.Response, error)
Host string
}

func New(cfg Config) (Client, error) {
Expand All @@ -33,12 +31,12 @@ func New(cfg Config) (Client, error) {
return http.DefaultClient.Do(req)
}

return Client{roundTrip, cfg.Host}, nil
return Client{roundTrip}, nil
}

// InitiateRun sends a request to Mint for starting a new run
func (c Client) InitiateRun(cfg InitiateRunConfig) (*InitiateRunResult, error) {
endpoint := c.mintEndpoint("/api/runs")
endpoint := "/mint/api/runs"

if err := cfg.Validate(); err != nil {
return nil, errors.Wrap(err, "validation failed")
Expand Down Expand Up @@ -106,11 +104,3 @@ func extractErrorMessage(reader io.Reader) string {

return errorStruct.Result.Data.Error
}

// TODO(TS): Remove this once we're fully transitioned
func (c Client) mintEndpoint(path string) string {
if !strings.Contains(c.Host, "cloud") {
return path
}
return "/mint" + path
}
114 changes: 36 additions & 78 deletions internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,42 @@ import (

var _ = Describe("Client", func() {
Describe("InitiateRun", func() {
Context("without a mint base path", func() {
It("uses an mint.rwx.com style endpoint", func() {
body := struct {
RunID string `json:"runId"`
RunURL string `json:"runUrl"`
TargetedTaskKeys []string `json:"targetedTaskKeys"`
DefinitionPath string `json:"definitionPath"`
}{
RunID: "123",
RunURL: "https://mint.rwx.com/runs/123",
TargetedTaskKeys: []string{},
DefinitionPath: "foo",
}
bodyBytes, _ := json.Marshal(body)

roundTrip := func(req *http.Request) (*http.Response, error) {
Expect(req.URL.Path).To(Equal("/api/runs"))
return &http.Response{
Status: "201 Created",
StatusCode: 201,
Body: io.NopCloser(bytes.NewReader(bodyBytes)),
}, nil
}

c := client.Client{roundTrip, "mint.rwx.com"}

initRunConfig := client.InitiateRunConfig{
InitializationParameters: map[string]string{},
TaskDefinitions: []client.TaskDefinition{
{Path: "foo", FileContents: "echo 'bar'"},
},
TargetedTaskKeys: []string{},
UseCache: false,
}

_, err := c.InitiateRun(initRunConfig)
Expect(err).To(BeNil())
})
})

Context("with a mint base path", func() {
It("prefixes the endpoint with the base path", func() {
body := struct {
RunID string `json:"runId"`
RunURL string `json:"runUrl"`
TargetedTaskKeys []string `json:"targetedTaskKeys"`
DefinitionPath string `json:"definitionPath"`
}{
RunID: "123",
RunURL: "https://mint.rwx.com/runs/123",
TargetedTaskKeys: []string{},
DefinitionPath: "foo",
}
bodyBytes, _ := json.Marshal(body)

roundTrip := func(req *http.Request) (*http.Response, error) {
Expect(req.URL.Path).To(Equal("/mint/api/runs"))
return &http.Response{
Status: "201 Created",
StatusCode: 201,
Body: io.NopCloser(bytes.NewReader(bodyBytes)),
}, nil
}

c := client.Client{roundTrip, "cloud.rwx.com"}

initRunConfig := client.InitiateRunConfig{
InitializationParameters: map[string]string{},
TaskDefinitions: []client.TaskDefinition{
{Path: "foo", FileContents: "echo 'bar'"},
},
TargetedTaskKeys: []string{},
UseCache: false,
}

_, err := c.InitiateRun(initRunConfig)
Expect(err).To(BeNil())
})
It("prefixes the endpoint with the base path", func() {
body := struct {
RunID string `json:"runId"`
RunURL string `json:"runUrl"`
TargetedTaskKeys []string `json:"targetedTaskKeys"`
DefinitionPath string `json:"definitionPath"`
}{
RunID: "123",
RunURL: "https://cloud.rwx.com/mint/org/runs/123",
TargetedTaskKeys: []string{},
DefinitionPath: "foo",
}
bodyBytes, _ := json.Marshal(body)

roundTrip := func(req *http.Request) (*http.Response, error) {
Expect(req.URL.Path).To(Equal("/mint/api/runs"))
return &http.Response{
Status: "201 Created",
StatusCode: 201,
Body: io.NopCloser(bytes.NewReader(bodyBytes)),
}, nil
}

c := client.Client{roundTrip}

initRunConfig := client.InitiateRunConfig{
InitializationParameters: map[string]string{},
TaskDefinitions: []client.TaskDefinition{
{Path: "foo", FileContents: "echo 'bar'"},
},
TargetedTaskKeys: []string{},
UseCache: false,
}

_, err := c.InitiateRun(initRunConfig)
Expect(err).To(BeNil())
})
})
})

0 comments on commit 77f249b

Please sign in to comment.