small refinement to clair client

This commit is contained in:
Tan Jiang 2017-06-25 11:44:56 +08:00
parent e0f01cfd09
commit ed296812f0
2 changed files with 5 additions and 6 deletions

View File

@ -56,8 +56,6 @@ func (c *Client) ScanLayer(l models.ClairLayer) error {
if err != nil {
return err
}
c.logger.Infof("endpoint: %s", c.endpoint)
c.logger.Infof("body: %s", string(data))
req, err := http.NewRequest("POST", c.endpoint+"/v1/layers", bytes.NewReader(data))
if err != nil {
return err
@ -68,13 +66,13 @@ func (c *Client) ScanLayer(l models.ClairLayer) error {
return err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
c.logger.Infof("response code: %d", resp.StatusCode)
if resp.StatusCode != http.StatusCreated {
c.logger.Warningf("Unexpected status code: %d", resp.StatusCode)
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
return fmt.Errorf("Unexpected status code: %d, text: %s", resp.StatusCode, string(b))
}
c.logger.Infof("Returning.")

View File

@ -65,6 +65,7 @@ func BuildBlobURL(endpoint, repository, digest string) string {
}
//GetTokenForRepo is a temp solution for job handler to get a token for clair.
//TODO: Get rid of it when it can get a token from repository client.
func GetTokenForRepo(repository string) (string, error) {
u, err := url.Parse(config.InternalTokenServiceEndpoint())
if err != nil {