github.com/jonsyu1/godel@v0.0.0-20171017211503-64567a0cf169/apps/distgo/params/manifest.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package params 16 17 import ( 18 "strings" 19 20 "github.com/pkg/errors" 21 "gopkg.in/yaml.v2" 22 ) 23 24 type slsManifest struct { 25 ManifestVersion string `yaml:"manifest-version"` 26 ProductGroup string `yaml:"product-group"` 27 ProductName string `yaml:"product-name"` 28 ProductVersion string `yaml:"product-version"` 29 ProductType string `yaml:"product-type,omitempty"` 30 Extensions map[string]interface{} `yaml:"extensions,omitempty"` 31 } 32 33 func GetManifest(groupID, name, version, productType string, extensions map[string]interface{}) (string, error) { 34 var missingRequired []string 35 if groupID == "" { 36 missingRequired = append(missingRequired, "group-id") 37 } 38 if name == "" { 39 missingRequired = append(missingRequired, "product-name") 40 } 41 if version == "" { 42 missingRequired = append(missingRequired, "product-version") 43 } 44 if len(missingRequired) > 0 { 45 return "", errors.Errorf("required properties were missing: %s", strings.Join(missingRequired, ", ")) 46 } 47 48 m := slsManifest{ 49 ManifestVersion: "1.0", 50 ProductGroup: groupID, 51 ProductName: name, 52 ProductVersion: version, 53 Extensions: extensions, 54 } 55 if productType != "" { 56 m.ProductType = productType 57 } 58 manifestBytes, err := yaml.Marshal(m) 59 if err != nil { 60 return "", errors.Wrapf(err, "failed to marshal %v as YAML", m) 61 } 62 return string(manifestBytes), nil 63 }