From 33035378a9dccf95a19ebffa32a3d8084a6dca39 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 23 Jun 2016 18:19:39 +0800 Subject: [PATCH 1/3] insecure https support when checking and creating project --- job/replication/transfer.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/job/replication/transfer.go b/job/replication/transfer.go index 0851b7fb9..3b0595358 100644 --- a/job/replication/transfer.go +++ b/job/replication/transfer.go @@ -17,6 +17,7 @@ package replication import ( "bytes" + "crypto/tls" "encoding/json" "errors" "fmt" @@ -190,7 +191,16 @@ func (c *Checker) projectExist() (exist, canWrite bool, err error) { } req.SetBasicAuth(c.dstUsr, c.dstPwd) - resp, err := http.DefaultClient.Do(req) + + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: c.insecure, + }, + }, + } + + resp, err := client.Do(req) if err != nil { return } @@ -259,12 +269,23 @@ func (c *Checker) createProject() error { } req.SetBasicAuth(c.dstUsr, c.dstPwd) - resp, err := http.DefaultClient.Do(req) + + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: c.insecure, + }, + }, + } + + resp, err := client.Do(req) if err != nil { return err } - if resp.StatusCode != http.StatusCreated { + // version 0.1.1's reponse code is 200 + if resp.StatusCode != http.StatusCreated || + resp.StatusCode != http.StatusOK { if resp.StatusCode == http.StatusConflict { return ErrConflict } From 543cb26da1d412139b486dcf6475f2a05d30497d Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 23 Jun 2016 18:23:40 +0800 Subject: [PATCH 2/3] update --- job/replication/transfer.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/job/replication/transfer.go b/job/replication/transfer.go index 3b0595358..ca9171bf8 100644 --- a/job/replication/transfer.go +++ b/job/replication/transfer.go @@ -284,22 +284,24 @@ func (c *Checker) createProject() error { } // version 0.1.1's reponse code is 200 - if resp.StatusCode != http.StatusCreated || - resp.StatusCode != http.StatusOK { - if resp.StatusCode == http.StatusConflict { - return ErrConflict - } - - defer resp.Body.Close() - message, err := ioutil.ReadAll(resp.Body) - if err != nil { - c.logger.Errorf("an error occurred while reading message from response: %v", err) - } - - return fmt.Errorf("failed to create project %s on %s with user %s: %d %s", - c.project, c.dstURL, c.dstUsr, resp.StatusCode, string(message)) + if resp.StatusCode == http.StatusCreated || + resp.StatusCode == http.StatusOK { + return nil } + if resp.StatusCode == http.StatusConflict { + return ErrConflict + } + + defer resp.Body.Close() + message, err := ioutil.ReadAll(resp.Body) + if err != nil { + c.logger.Errorf("an error occurred while reading message from response: %v", err) + } + + return fmt.Errorf("failed to create project %s on %s with user %s: %d %s", + c.project, c.dstURL, c.dstUsr, resp.StatusCode, string(message)) + return nil } From a1b3a07d39b63a757caedc9ea198a62383e1d36b Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 23 Jun 2016 18:35:22 +0800 Subject: [PATCH 3/3] pass govet --- job/replication/transfer.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/job/replication/transfer.go b/job/replication/transfer.go index ca9171bf8..30bbf88ae 100644 --- a/job/replication/transfer.go +++ b/job/replication/transfer.go @@ -301,8 +301,6 @@ func (c *Checker) createProject() error { return fmt.Errorf("failed to create project %s on %s with user %s: %d %s", c.project, c.dstURL, c.dstUsr, resp.StatusCode, string(message)) - - return nil } // ManifestPuller pulls the manifest of a tag. And if no tag needs to be pulled,