@@ -16,12 +16,9 @@ limitations under the License.
1616package main
1717
1818import (
19- "crypto/tls"
20- "crypto/x509"
2119 "errors"
2220 "io"
2321 "io/ioutil"
24- "net/http"
2522 "os"
2623 "os/exec"
2724 "os/user"
@@ -30,6 +27,7 @@ import (
3027 "github.com/ot4i/ace-docker/internal/command"
3128 "github.com/ot4i/ace-docker/internal/name"
3229 "github.com/ot4i/ace-docker/internal/qmgr"
30+ "github.com/ot4i/ace-docker/internal/contentserver"
3331 "gopkg.in/yaml.v2"
3432)
3533
@@ -464,57 +462,24 @@ func getConfigurationFromContentServer() error {
464462 return errors .New ("CONTENT_SERVER_CA not defined" )
465463 }
466464 }
465+
467466 log .Printf ("Using ca file %s" , contentServerCACert )
468467 caCert , err := ioutil .ReadFile (contentServerCACert )
469468 if err != nil {
470469 log .Errorf ("Error reading CA Certificate" )
471470 return errors .New ("Error reading CA Certificate" )
472471 }
473- caCertPool := x509 .NewCertPool ()
474- caCertPool .AppendCertsFromPEM (caCert )
475472
476- // If provided read the key pair to create certificate
477473 contentServerCert := os .Getenv ("CONTENT_SERVER_CERT" )
478474 contentServerKey := os .Getenv ("CONTENT_SERVER_KEY" )
479- cert , err := tls .LoadX509KeyPair (contentServerCert , contentServerKey )
480- if err != nil {
481- if contentServerCert != "" && contentServerKey != "" {
482- log .Errorf ("Error reading Certificates: %s" , err )
483- return errors .New ("Error reading Certificates" )
484- }
485- } else {
486- log .Printf ("Using certs for mutual auth" )
487- }
488-
489- client := & http.Client {
490- Transport : & http.Transport {
491- TLSClientConfig : & tls.Config {
492- RootCAs : caCertPool ,
493- Certificates : []tls.Certificate {cert },
494- ServerName : serverName ,
495- },
496- },
497- }
498475
499- request , err := http . NewRequest ( "GET" , url , nil )
476+ bar , err := contentserver . GetBAR ( url , serverName , token , caCert , contentServerCert , contentServerKey , log )
500477 if err != nil {
501- log .Errorf ("Error creating request for content server" )
502- return err
503- }
504-
505- request .Header .Set ("x-ibm-ace-directory-token" , token )
506- response , err := client .Do (request )
507- if err != nil {
508- log .Errorf ("Error downloading from %v: %v" , url , err )
509- return err
510- }
511- if response .StatusCode != 200 {
512- log .Errorf ("Error downloading from %v: %v" , url , response .Status )
513478 return err
514479 }
480+ defer bar .Close ()
515481
516- defer response .Body .Close ()
517- _ , err = io .Copy (file , response .Body )
482+ _ , err = io .Copy (file , bar )
518483 if err != nil {
519484 log .Errorf ("Error writing file %v: %v" , file , err )
520485 return err
0 commit comments