github.com/jfrog/jfrog-client-go@v1.40.2/distribution/services/utils/distributionutils.go (about) 1 package utils 2 3 import ( 4 rtUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" 5 "github.com/jfrog/jfrog-client-go/utils/distribution" 6 ) 7 8 type ReleaseNotesSyntax string 9 10 const ( 11 Markdown ReleaseNotesSyntax = "markdown" 12 Asciidoc ReleaseNotesSyntax = "asciidoc" 13 PlainText ReleaseNotesSyntax = "plain_text" 14 ) 15 16 type ReleaseBundleParams struct { 17 SpecFiles []*rtUtils.CommonParams 18 Name string 19 Version string 20 SignImmediately bool 21 StoringRepository string 22 Description string 23 ReleaseNotes string 24 ReleaseNotesSyntax ReleaseNotesSyntax 25 GpgPassphrase string 26 } 27 28 func NewReleaseBundleParams(name, version string) ReleaseBundleParams { 29 return ReleaseBundleParams{ 30 Name: name, 31 Version: version, 32 } 33 } 34 35 func CreateBundleBody(releaseBundleParams ReleaseBundleParams, dryRun bool) (*ReleaseBundleBody, error) { 36 var bundleQueries []BundleQuery 37 var pathMappings []rtUtils.PathMapping 38 39 // Create release bundle queries 40 for _, specFile := range releaseBundleParams.SpecFiles { 41 // Create path mapping 42 if specFile.GetSpecType() == rtUtils.AQL { 43 pathMappings = distribution.CreatePathMappings(specFile.PathMapping.Input, specFile.PathMapping.Output) 44 } else { 45 pathMappings = distribution.CreatePathMappingsFromPatternAndTarget(specFile.Pattern, specFile.Target) 46 } 47 48 // Create AQL 49 aql, err := createAql(specFile) 50 if err != nil { 51 return nil, err 52 } 53 54 // Create added properties 55 addedProps := createAddedProps(specFile) 56 57 // Append bundle query 58 bundleQueries = append(bundleQueries, BundleQuery{Aql: aql, PathMappings: pathMappings, AddedProps: addedProps}) 59 } 60 61 // Create release bundle struct 62 releaseBundleBody := &ReleaseBundleBody{ 63 DryRun: dryRun, 64 SignImmediately: &releaseBundleParams.SignImmediately, 65 StoringRepository: releaseBundleParams.StoringRepository, 66 Description: releaseBundleParams.Description, 67 BundleSpec: BundleSpec{ 68 Queries: bundleQueries, 69 }, 70 } 71 72 // Add release notes if needed 73 if releaseBundleParams.ReleaseNotes != "" { 74 releaseBundleBody.ReleaseNotes = &ReleaseNotes{ 75 Syntax: releaseBundleParams.ReleaseNotesSyntax, 76 Content: releaseBundleParams.ReleaseNotes, 77 } 78 } 79 return releaseBundleBody, nil 80 } 81 82 // Create the AQL query from the input spec 83 func createAql(specFile *rtUtils.CommonParams) (string, error) { 84 if specFile.GetSpecType() != rtUtils.AQL { 85 query, err := rtUtils.CreateAqlBodyForSpecWithPattern(specFile) 86 if err != nil { 87 return "", err 88 } 89 specFile.Aql = rtUtils.Aql{ItemsFind: query} 90 } 91 return rtUtils.BuildQueryFromSpecFile(specFile, rtUtils.NONE), nil 92 } 93 94 // Create the AddedProps array from the input TargetProps string 95 func createAddedProps(specFile *rtUtils.CommonParams) []AddedProps { 96 props := specFile.TargetProps 97 98 var addedProps []AddedProps 99 if props != nil { 100 for key, values := range props.ToMap() { 101 addedProps = append(addedProps, AddedProps{key, values}) 102 } 103 } 104 return addedProps 105 } 106 107 func AddGpgPassphraseHeader(gpgPassphrase string, headers *map[string]string) { 108 if gpgPassphrase != "" { 109 rtUtils.AddHeader("X-GPG-PASSPHRASE", gpgPassphrase, headers) 110 } 111 }