diff --git a/go/models/deploy.go b/go/models/deploy.go index c151f676..46f3f385 100644 --- a/go/models/deploy.go +++ b/go/models/deploy.go @@ -8,6 +8,7 @@ package models import ( strfmt "github.com/go-openapi/strfmt" + "github.com/go-openapi/errors" "github.com/go-openapi/swag" ) @@ -75,6 +76,9 @@ type Deploy struct { // screenshot url ScreenshotURL string `json:"screenshot_url,omitempty"` + // site capabilities + SiteCapabilities *DeploySiteCapabilities `json:"site_capabilities,omitempty"` + // site id SiteID string `json:"site_id,omitempty"` @@ -102,6 +106,33 @@ type Deploy struct { // Validate validates this deploy func (m *Deploy) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateSiteCapabilities(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Deploy) validateSiteCapabilities(formats strfmt.Registry) error { + + if swag.IsZero(m.SiteCapabilities) { // not required + return nil + } + + if m.SiteCapabilities != nil { + if err := m.SiteCapabilities.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("site_capabilities") + } + return err + } + } + return nil } diff --git a/go/models/deploy_site_capabilities.go b/go/models/deploy_site_capabilities.go new file mode 100644 index 00000000..5c076b54 --- /dev/null +++ b/go/models/deploy_site_capabilities.go @@ -0,0 +1,43 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + strfmt "github.com/go-openapi/strfmt" + + "github.com/go-openapi/swag" +) + +// DeploySiteCapabilities deploy site capabilities +// swagger:model deploySiteCapabilities +type DeploySiteCapabilities struct { + + // asset management + AssetManagement bool `json:"asset_management,omitempty"` +} + +// Validate validates this deploy site capabilities +func (m *DeploySiteCapabilities) Validate(formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *DeploySiteCapabilities) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *DeploySiteCapabilities) UnmarshalBinary(b []byte) error { + var res DeploySiteCapabilities + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/go/porcelain/deploy.go b/go/porcelain/deploy.go index 236bef1c..ae789d19 100644 --- a/go/porcelain/deploy.go +++ b/go/porcelain/deploy.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "os" "path/filepath" + "regexp" "strings" "sync" "time" @@ -161,7 +162,7 @@ func (n *Netlify) DoDeploy(ctx context.Context, options *DeployOptions, deploy * } } - files, err := walk(options.Dir, options.Observer) + files, err := walk(options.Dir, options.Observer, deploy.SiteCapabilities.AssetManagement) if err != nil { if options.Observer != nil { options.Observer.OnFailedWalk() @@ -451,7 +452,7 @@ func (n *Netlify) uploadFile(ctx context.Context, d *models.Deploy, f *FileBundl } } -func walk(dir string, observer DeployObserver) (*deployFiles, error) { +func walk(dir string, observer DeployObserver, useAssetManagement bool) (*deployFiles, error) { files := newDeployFiles() err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { @@ -487,6 +488,13 @@ func walk(dir string, observer DeployObserver) (*deployFiles, error) { } file.Sum = hex.EncodeToString(s.Sum(nil)) + if useAssetManagement { + originalSha := getAssetManagementSha(o) + if originalSha != "" { + file.Sum += ":" + string(originalSha) + } + } + files.Add(rel, file) if observer != nil { @@ -634,3 +642,19 @@ func createHeader(archive *zip.Writer, i os.FileInfo, runtime string) (io.Writer } return archive.Create(i.Name()) } + +func getAssetManagementSha(file io.Reader) string { + // currently this only supports certain type of git lfs pointer files + // version [version]\noid sha256:[oid]\nsize [size] + data := make([]byte, 150) + if count, err := file.Read(data); err == nil { + r, _ := regexp.Compile(`^version \S+\noid sha256:(\S+)\n`) + res := r.FindSubmatch(data[:count]) + if len(res) == 2 { + if originalSha := res[1]; len(originalSha) == 64 { + return string(originalSha) + } + } + } + return "" +} diff --git a/go/porcelain/deploy_test.go b/go/porcelain/deploy_test.go new file mode 100644 index 00000000..c25fff90 --- /dev/null +++ b/go/porcelain/deploy_test.go @@ -0,0 +1,26 @@ +package porcelain + +import ( + "strings" + "testing" +) + +func TestGetAssetManagementSha(t *testing.T) { + tests := []struct { + contents string + length int + }{ + {"Not a pointer file", 0}, + {"version https://git-lfs.github.com/spec/v1\n" + + "oid sha256:7e56e498ccb4cbb9c672e1aed6710fb91b2fd314394a666c11c33b2059ea3d71\n" + + "size 1743570", 64}, + } + + for _, test := range tests { + file := strings.NewReader(test.contents) + out := getAssetManagementSha(file) + if len(out) != test.length { + t.Fatalf("expected `%d`, got `%d`", test.length, len(out)) + } + } +} diff --git a/swagger.yml b/swagger.yml index 20a588fa..7d54d99e 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1566,6 +1566,11 @@ definitions: type: boolean review_url: type: string + site_capabilities: + type: object + properties: + asset_management: + type: boolean deployFiles: type: object properties: