Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/spaces/model_cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
6 changes: 3 additions & 3 deletions client/spaces/protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)}
}
Expand Down
6 changes: 0 additions & 6 deletions spacefile/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
}
Expand Down
4 changes: 4 additions & 0 deletions spacefile/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions spacefile/types_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
12 changes: 11 additions & 1 deletion spacefile/types_swlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package spacefile

import (
"fmt"
"regexp"
"strings"

"github.com/fatih/color"
"github.com/spf13/viper"
Expand Down Expand Up @@ -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())
}
Expand Down
8 changes: 7 additions & 1 deletion spacefile/types_swlist_test.go
Original file line number Diff line number Diff line change
@@ -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"}}
Expand Down