Merge pull request #402 from ywk253100/bug_fix_for_access_log

insecure https support when checking and creating project
This commit is contained in:
Wenkai Yin 2016-06-23 20:09:32 +08:00 committed by GitHub
commit 1dabbc6427

View File

@ -17,6 +17,7 @@ package replication
import ( import (
"bytes" "bytes"
"crypto/tls"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -190,7 +191,16 @@ func (c *Checker) projectExist() (exist, canWrite bool, err error) {
} }
req.SetBasicAuth(c.dstUsr, c.dstPwd) 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 { if err != nil {
return return
} }
@ -259,27 +269,38 @@ func (c *Checker) createProject() error {
} }
req.SetBasicAuth(c.dstUsr, c.dstPwd) 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 { if err != nil {
return err return err
} }
if resp.StatusCode != http.StatusCreated { // version 0.1.1's reponse code is 200
if resp.StatusCode == http.StatusConflict { if resp.StatusCode == http.StatusCreated ||
return ErrConflict resp.StatusCode == http.StatusOK {
} return nil
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 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))
} }
// ManifestPuller pulls the manifest of a tag. And if no tag needs to be pulled, // ManifestPuller pulls the manifest of a tag. And if no tag needs to be pulled,