Skip to content

Commit

Permalink
Merge pull request #19 from thestormforge/relations
Browse files Browse the repository at this point in the history
Change relations from carbonrelay.com to stormforge.io
  • Loading branch information
jgustie authored May 24, 2021
2 parents cc14647 + b30966f commit 2a00df6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
35 changes: 32 additions & 3 deletions pkg/api/experiments/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"

"golang.org/x/oauth2"
Expand All @@ -34,11 +35,39 @@ const (
relationNext = "next"
relationPrev = "prev"
relationPrevious = "previous"
relationLabels = "https://carbonrelay.com/rel/labels"
relationTrials = "https://carbonrelay.com/rel/trials"
relationNextTrial = "https://carbonrelay.com/rel/next-trial"
relationLabels = "https://stormforge.io/rel/labels"
relationTrials = "https://stormforge.io/rel/trials"
relationNextTrial = "https://stormforge.io/rel/next-trial"
)

// matchRel checks to see if a relation value matches an expected value. For
// standard relations, this is simply a case-insensitive equality test; for
// private relations this function will also test for previously known
// equivalent relations.
func matchRel(rel, expected string) bool {
rel = strings.ToLower(rel)
expected = strings.ToLower(expected)
switch expected {

case relationLabels:
return rel == relationLabels ||
rel == "https://carbonrelay.com/rel/labels" ||
rel == "https://carbonrelay.com/rel/triallabels"

case relationTrials:
return rel == relationTrials ||
rel == "https://carbonrelay.com/rel/trials"

case relationNextTrial:
return rel == relationNextTrial ||
rel == "https://carbonrelay.com/rel/next-trial" ||
rel == "https://carbonrelay.com/rel/nexttrial"

default:
return rel == expected
}
}

// Meta is used to collect resource metadata from the response
type Meta interface {
SetLocation(string)
Expand Down
15 changes: 5 additions & 10 deletions pkg/api/experiments/v1alpha1/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,16 @@ func (m *ExperimentMeta) SetLastModified(lastModified time.Time) {
m.LastModified = lastModified
}
func (m *ExperimentMeta) SetLink(rel, link string) {
switch strings.ToLower(rel) {
case relationSelf:
switch {
case matchRel(rel, relationSelf):
m.SelfURL = link
case relationTrials:
case matchRel(rel, relationTrials):
m.TrialsURL = link
case relationNextTrial:
case matchRel(rel, relationNextTrial):
m.NextTrialURL = link
case relationLabels:
case matchRel(rel, relationLabels):
m.LabelsURL = link
}

// Backwards compatibility with the old next trial relation
if m.NextTrialURL == "" && strings.ToLower(rel) == "https://carbonrelay.com/rel/nexttrial" {
m.NextTrialURL = link
}
}
func (m *ExperimentMeta) Headers() http.Header {
h := metaMarshal("", m.LastModified)
Expand Down
9 changes: 2 additions & 7 deletions pkg/api/experiments/v1alpha1/trial.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ type TrialMeta struct {
func (m *TrialMeta) SetLocation(location string) { m.SelfURL = location }
func (m *TrialMeta) SetLastModified(time.Time) {}
func (m *TrialMeta) SetLink(rel, link string) {
switch strings.ToLower(rel) {
case relationLabels:
m.LabelsURL = link
}

// Backwards compatibility with the old trial labels relation
if m.LabelsURL == "" && strings.ToLower(rel) == "https://carbonrelay.com/rel/triallabels" {
switch {
case matchRel(rel, relationLabels):
m.LabelsURL = link
}
}
Expand Down

0 comments on commit 2a00df6

Please sign in to comment.