@@ -30,28 +30,45 @@ var (
3030 _ aptly.PublishedStorage = (* PublishedStorage )(nil )
3131)
3232
33- // NewPublishedStorageRaw creates jfrog PublishedStorage from raw connection specs
34- func NewPublishedStorageRaw (
35- repository , url , user , password , apiKey , accessToken , prefix string ,
36- plusWorkaround , debug bool ,
37- ) (* PublishedStorage , error ) {
38-
33+ func createPublishedStorageConfig (url , user , password , apiKey , accessToken string ) (config.Config , error ) {
3934 artDetails := auth .NewArtifactoryDetails ()
4035 artDetails .SetUrl (url )
36+
37+ if user == "" {
38+ user = os .Getenv ("JFROG_USERNAME" );
39+ }
40+ if password == "" {
41+ password = os .Getenv ("JFROG_PASSWORD" );
42+ }
43+ if apiKey == "" {
44+ apiKey = os .Getenv ("JFROG_APIKEY" );
45+ }
46+ if accessToken == "" {
47+ accessToken = os .Getenv ("JFROG_ACCESSTOKEN" );
48+ }
49+
4150 if user != "" && password != "" {
42- artDetails .SetUser (user )
43- artDetails .SetPassword (password )
51+ artDetails .SetUser (user )
52+ artDetails .SetPassword (password )
4453 } else if apiKey != "" {
45- artDetails .SetApiKey (apiKey )
54+ artDetails .SetApiKey (apiKey )
4655 } else if accessToken != "" {
4756 artDetails .SetAccessToken (accessToken )
48- }
57+ }
4958
50- serviceConfig , err := config .NewConfigBuilder ().
59+ return config .NewConfigBuilder ().
5160 SetServiceDetails (artDetails ).
5261 SetDryRun (false ).
5362 Build ()
54-
63+ }
64+
65+ // NewPublishedStorageRaw creates jfrog PublishedStorage from raw connection specs
66+ func NewPublishedStorageRaw (
67+ repository , url , user , password , apiKey , accessToken , prefix string ,
68+ plusWorkaround , debug bool ,
69+ ) (* PublishedStorage , error ) {
70+
71+ serviceConfig , err := createPublishedStorageConfig (url , user , password , apiKey , accessToken )
5572 if err != nil {
5673 return nil , errors .Wrap (err , "error building jfrog client config" )
5774 }
@@ -91,7 +108,7 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
91108 if storage .plusWorkaround {
92109 targetPath = strings .Replace (targetPath , "+" , "%2B" , - 1 )
93110 }
94-
111+
95112 params := services .NewUploadParams ()
96113 params .Pattern = sourceFilename
97114 params .Target = targetPath
@@ -106,7 +123,7 @@ func (storage *PublishedStorage) Remove(path string) error {
106123 if storage .plusWorkaround {
107124 targetPath = strings .Replace (targetPath , "+" , "%2B" , - 1 )
108125 }
109-
126+
110127 deleteParams := services .NewDeleteParams ()
111128 deleteParams .SetPattern (targetPath )
112129
@@ -175,7 +192,7 @@ func (storage *PublishedStorage) Filelist(prefix string) ([]string, error) {
175192 return nil , err
176193 }
177194 defer reader .Close ()
178-
195+
179196 var paths []string
180197
181198 for element := new (utils.ResultItem ); reader .NextRecord (element ) == nil ; element = new (utils.ResultItem ) {
@@ -186,19 +203,19 @@ func (storage *PublishedStorage) Filelist(prefix string) ([]string, error) {
186203 }
187204 paths = append (paths , relPath )
188205 }
189-
206+
190207 return paths , nil
191208}
192209
193210func (storage * PublishedStorage ) RenameFile (oldName , newName string ) error {
194211 oldTarget := filepath .Join (storage .repository , storage .prefix , oldName )
195212 newTarget := filepath .Join (storage .repository , storage .prefix , newName )
196-
213+
197214 if storage .plusWorkaround {
198215 oldTarget = strings .Replace (oldTarget , "+" , "%2B" , - 1 )
199216 newTarget = strings .Replace (newTarget , "+" , "%2B" , - 1 )
200217 }
201-
218+
202219 params := services .NewMoveCopyParams ()
203220 params .Pattern = oldTarget
204221 params .Target = newTarget
@@ -211,17 +228,17 @@ func (storage *PublishedStorage) RenameFile(oldName, newName string) error {
211228func (storage * PublishedStorage ) SymLink (src string , dst string ) error {
212229 oldTarget := filepath .Join (storage .repository , storage .prefix , src )
213230 newTarget := filepath .Join (storage .repository , storage .prefix , dst )
214-
231+
215232 if storage .plusWorkaround {
216233 oldTarget = strings .Replace (oldTarget , "+" , "%2B" , - 1 )
217234 newTarget = strings .Replace (newTarget , "+" , "%2B" , - 1 )
218235 }
219-
236+
220237 params := services .NewMoveCopyParams ()
221238 params .Pattern = oldTarget
222239 params .Target = newTarget
223240 params .Flat = true
224-
241+
225242 props := utils .NewProperties ()
226243 props .AddProperty ("SymLink" , src )
227244 params .SetTargetProps (props )
@@ -239,7 +256,7 @@ func (storage *PublishedStorage) FileExists(path string) (bool, error) {
239256 if storage .plusWorkaround {
240257 targetPath = strings .Replace (targetPath , "+" , "%2B" , - 1 )
241258 }
242-
259+
243260 params := services .NewSearchParams ()
244261 params .Pattern = targetPath
245262
@@ -248,7 +265,7 @@ func (storage *PublishedStorage) FileExists(path string) (bool, error) {
248265 return false , err
249266 }
250267 defer reader .Close ()
251-
268+
252269 length , err := reader .Length ()
253270 isEmpty := length == 0
254271 return ! isEmpty , err
@@ -259,17 +276,17 @@ func (storage *PublishedStorage) ReadLink(path string) (string, error) {
259276 if storage .plusWorkaround {
260277 targetPath = strings .Replace (targetPath , "+" , "%2B" , - 1 )
261278 }
262-
279+
263280 props , err := storage .manager .GetItemProps (targetPath )
264281 if err != nil {
265282 return "" , nil
266283 }
267-
284+
268285 for k , v := range props .Properties {
269286 if k == "SymLink" && len (v ) > 0 {
270287 return v [0 ], nil
271288 }
272289 }
273-
290+
274291 return "" , nil
275292}
0 commit comments