@@ -117,7 +117,12 @@ func (context *AptlyContext) config() *utils.ConfigStructure {
117117 if err != nil {
118118 fmt .Fprintf (os .Stderr , "Config file not found, creating default config at %s\n \n " , homeLocation )
119119
120- _ = utils .SaveConfigRaw (homeLocation , aptly .AptlyConf )
120+ defaultConfig := aptly .AptlyConf
121+ if len (defaultConfig ) == 0 {
122+ defaultConfig = []byte ("root_dir: \" \" " )
123+ }
124+
125+ _ = utils .SaveConfigRaw (homeLocation , defaultConfig )
121126 err = utils .LoadConfig (homeLocation , & utils .Config )
122127 if err != nil {
123128 Fatal (fmt .Errorf ("error loading config file %s: %s" , homeLocation , err ))
@@ -408,8 +413,8 @@ func (context *AptlyContext) PackagePool() aptly.PackagePool {
408413 return context .packagePool
409414}
410415
411- // GetPublishedStorage returns instance of PublishedStorage
412- func (context * AptlyContext ) GetPublishedStorage (name string ) aptly.PublishedStorage {
416+ // GetPublishedStorage returns instance of PublishedStorage, or an error if the storage is not configured
417+ func (context * AptlyContext ) GetPublishedStorage (name string ) ( aptly.PublishedStorage , error ) {
413418 context .Lock ()
414419 defer context .Unlock ()
415420
@@ -420,14 +425,14 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
420425 } else if strings .HasPrefix (name , "filesystem:" ) {
421426 params , ok := context .config ().FileSystemPublishRoots [name [11 :]]
422427 if ! ok {
423- Fatal ( fmt .Errorf ("published local storage %v not configured" , name [11 :]) )
428+ return nil , fmt .Errorf ("published local storage %v not configured" , name [11 :])
424429 }
425430
426431 publishedStorage = files .NewPublishedStorage (params .RootDir , params .LinkMethod , params .VerifyMethod )
427432 } else if strings .HasPrefix (name , "s3:" ) {
428433 params , ok := context .config ().S3PublishRoots [name [3 :]]
429434 if ! ok {
430- Fatal ( fmt .Errorf ("published S3 storage %v not configured" , name [3 :]) )
435+ return nil , fmt .Errorf ("published S3 storage %v not configured" , name [3 :])
431436 }
432437
433438 var err error
@@ -437,12 +442,12 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
437442 params .EncryptionMethod , params .PlusWorkaround , params .DisableMultiDel ,
438443 params .ForceSigV2 , params .ForceVirtualHostedStyle , params .Debug )
439444 if err != nil {
440- Fatal ( err )
445+ return nil , err
441446 }
442447 } else if strings .HasPrefix (name , "gcs:" ) {
443448 params , ok := context .config ().GCSPublishRoots [name [4 :]]
444449 if ! ok {
445- Fatal ( fmt .Errorf ("published GCS storage %v not configured" , name [4 :]) )
450+ return nil , fmt .Errorf ("published GCS storage %v not configured" , name [4 :])
446451 }
447452
448453 var err error
@@ -451,51 +456,51 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto
451456 params .Project , params .Endpoint , params .ACL , params .StorageClass , params .EncryptionKey ,
452457 params .DisableMultiDel , params .Debug )
453458 if err != nil {
454- Fatal ( err )
459+ return nil , err
455460 }
456461 } else if strings .HasPrefix (name , "swift:" ) {
457462 params , ok := context .config ().SwiftPublishRoots [name [6 :]]
458463 if ! ok {
459- Fatal ( fmt .Errorf ("published Swift storage %v not configured" , name [6 :]) )
464+ return nil , fmt .Errorf ("published Swift storage %v not configured" , name [6 :])
460465 }
461466
462467 var err error
463468 publishedStorage , err = swift .NewPublishedStorage (params .UserName , params .Password ,
464469 params .AuthURL , params .Tenant , params .TenantID , params .Domain , params .DomainID , params .TenantDomain , params .TenantDomainID , params .Container , params .Prefix )
465470 if err != nil {
466- Fatal ( err )
471+ return nil , err
467472 }
468473 } else if strings .HasPrefix (name , "azure:" ) {
469474 params , ok := context .config ().AzurePublishRoots [name [6 :]]
470475 if ! ok {
471- Fatal ( fmt .Errorf ("published Azure storage %v not configured" , name [6 :]) )
476+ return nil , fmt .Errorf ("published Azure storage %v not configured" , name [6 :])
472477 }
473478
474479 var err error
475480 publishedStorage , err = azure .NewPublishedStorage (
476481 params .AccountName , params .AccountKey , params .Container , params .Prefix , params .Endpoint )
477482 if err != nil {
478- Fatal ( err )
483+ return nil , err
479484 }
480485 } else if strings .HasPrefix (name , "jfrog:" ) {
481486 params , ok := context .config ().JFrogPublishRoots [name [6 :]]
482487 if ! ok {
483- Fatal ( fmt .Errorf ("published JFrog storage %v not configured" , name [6 :]) )
488+ return nil , fmt .Errorf ("published JFrog storage %v not configured" , name [6 :])
484489 }
485490
486491 var err error
487492 publishedStorage , err = jfrog .NewPublishedStorage (
488493 name [6 :], params )
489494 if err != nil {
490- Fatal ( err )
495+ return nil , fmt . Errorf ( "error creating jfrog manager: %w" , err )
491496 }
492497 } else {
493- Fatal ( fmt .Errorf ("unknown published storage format: %v" , name ) )
498+ return nil , fmt .Errorf ("unknown published storage format: %v" , name )
494499 }
495500 context .publishedStorages [name ] = publishedStorage
496501 }
497502
498- return publishedStorage
503+ return publishedStorage , nil
499504}
500505
501506// UploadPath builds path to upload storage
0 commit comments