diff --git a/client/spaces/model_cron.go b/client/spaces/model_cron.go index 1a607b9..db858be 100644 --- a/client/spaces/model_cron.go +++ b/client/spaces/model_cron.go @@ -7,6 +7,7 @@ type Cronjob struct { Schedule string `json:"schedule"` AllowParallel bool `json:"allowParallel"` Job CronjobJob `json:"job"` + ReadOnly bool `json:"readonly"` Timezone string `json:"timezone"` } diff --git a/client/spaces/protection.go b/client/spaces/protection.go index af8ab57..d8b9d0a 100644 --- a/client/spaces/protection.go +++ b/client/spaces/protection.go @@ -2,9 +2,10 @@ package spaces import ( "fmt" - "github.com/mittwald/spacectl/client/lowlevel" "net/url" + "github.com/mittwald/spacectl/client/lowlevel" + "github.com/mittwald/spacectl/client/errors" ) @@ -40,9 +41,8 @@ func (c *spacesClient) CreateStageProtection(spaceID, stage string, inputProtect // DeleteStageProtection disables the Stage Protection for the given stage func (c *spacesClient) DeleteStageProtection(spaceID, stage string) error { - var target Empty deletePath := fmt.Sprintf("/spaces/%s/stages/%s/protection", url.PathEscape(spaceID), url.PathEscape(stage)) - err := c.client.Delete(deletePath, &target) + err := c.client.Delete(deletePath, nil) if err != nil { return errors.ErrNested{Inner: err, Msg: fmt.Sprintf("could not delete protection for space: %s, stage: %s", spaceID, stage)} } diff --git a/spacefile/decl.go b/spacefile/decl.go index 839760a..9c8da3d 100644 --- a/spacefile/decl.go +++ b/spacefile/decl.go @@ -74,11 +74,6 @@ func FromSpace(decl *spaces.Space, api client.SpacesClient) (*SpaceDef, error) { UserData: st.UserData, } - cronjobDefs := make(CronjobDefList, len(st.Cronjobs)) - for i := range st.Cronjobs { - cronjobDefs[i] = CronjobFromDeclaration(&st.Cronjobs[i]) - } - databaseDefs := make(SoftwareDefList, len(st.Databases)) for i := range st.Databases { databaseDefs[i] = SoftwareDef{ @@ -96,7 +91,6 @@ func FromSpace(decl *spaces.Space, api client.SpacesClient) (*SpaceDef, error) { stageDef := StageDef{ Name: st.Name, Applications: appDefs, - Cronjobs: cronjobDefs, Databases: databaseDefs, Protection: protection.ProtectionType, } diff --git a/spacefile/hcl.go b/spacefile/hcl.go index d18659b..c903183 100644 --- a/spacefile/hcl.go +++ b/spacefile/hcl.go @@ -23,6 +23,10 @@ func unfuckHCL(in interface{}, path string) (interface{}, error) { in = mapped[0] case []map[string]interface{}: + if len(mapped) == 0 { + return nil, nil + } + for key := range mapped { for subKey := range mapped[key] { mapped[0][subKey], err = unfuckHCL(mapped[key][subKey], path+".0."+subKey) diff --git a/spacefile/types_stage.go b/spacefile/types_stage.go index f1dc124..ea11ef8 100644 --- a/spacefile/types_stage.go +++ b/spacefile/types_stage.go @@ -65,6 +65,15 @@ func (d *StageDef) resolveUserData() error { } } + for i := range d.Databases { + d.Databases[i].UserData, err = unfuckHCL(d.Databases[i].UserData, "") + mErr = multierror.Append(mErr, err) + + if d.Databases[i].UserData == nil { + d.Databases[i].UserData = map[string]string{} + } + } + return mErr.ErrorOrNil() } diff --git a/spacefile/types_swlist.go b/spacefile/types_swlist.go index d0d9acd..ee57ba7 100644 --- a/spacefile/types_swlist.go +++ b/spacefile/types_swlist.go @@ -2,6 +2,8 @@ package spacefile import ( "fmt" + "regexp" + "strings" "github.com/fatih/color" "github.com/spf13/viper" @@ -52,9 +54,17 @@ func (l SoftwareDefList) Merge(other SoftwareDefList) (SoftwareDefList, error) { return merged, nil } +// sanitizes semver declarations like this: >=5.7.0 <6.0.0 +// to go supported semver, which requires a comma between versions +func sanitizeSemver(ver string) string { + sepVersion := regexp.MustCompile(`(\s+)([0-9])`) // make sure no other whitespace exists + ver = sepVersion.ReplaceAllString(ver, "$2") + return strings.Replace(ver, " ", ", ", 1) // replace whitespace +} + // Validate performs (optional) online validation of software version and name func (s SoftwareDef) Validate(offline bool) error { - constraint, errSem := semver.NewConstraint(s.Version) + constraint, errSem := semver.NewConstraint(sanitizeSemver(s.Version)) if errSem != nil { return fmt.Errorf("version: %s", errSem.Error()) } diff --git a/spacefile/types_swlist_test.go b/spacefile/types_swlist_test.go index b54faf1..c99f86f 100644 --- a/spacefile/types_swlist_test.go +++ b/spacefile/types_swlist_test.go @@ -1,10 +1,16 @@ package spacefile import ( - "github.com/stretchr/testify/require" "testing" + + "github.com/stretchr/testify/require" ) +func TestSemverSanitize(t *testing.T) { + ver := "<= 1.2.3 >= 2.4.5" + require.Equal(t, sanitizeSemver(ver), "<=1.2.3, >=2.4.5") +} + func TestNewSoftwareIsAdded(t *testing.T) { base := SoftwareDefList{SoftwareDef{Identifier: "typo3", Version: "1.2.3"}} overlay := SoftwareDefList{SoftwareDef{Identifier: "magento", Version: "3.2.1"}}