Example #1
0
func writeConfigFile(logins loginMapping, file string) error {
	s, err := xstrings.ToIndentJSON(logins)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(file, s, os.ModePerm)
	if err != nil {
		return err
	}
	return nil
}
Example #2
0
func AnalyseHandler(rw http.ResponseWriter, request *http.Request) error {
	local := request.URL.Query()["local"]

	docker.IsLocal = len(local) > 0
	logrus.Debugf("Hyperclair is local: %v", docker.IsLocal)

	var err error
	var image docker.Image

	if !docker.IsLocal {
		image, err = docker.Pull(parseImageURL(request))

		if err != nil {
			return err
		}

	} else {
		image, err = docker.Parse(parseImageURL(request))
		if err != nil {
			return err
		}
		docker.FromHistory(&image)
		if err != nil {
			return err
		}
	}

	analyses := docker.Analyse(image)
	analysesJSON, err := xstrings.ToIndentJSON(analyses)
	if err != nil {
		return err
	}

	rw.Header().Set("Content-Type", "application/json")
	fmt.Fprint(rw, string(analysesJSON))
	return nil
}
Example #3
0
		var usr user
		fmt.Print("Username: "******"Password: "******"\n")
		encryptedPwd, err := bcrypt.GenerateFromPassword(pwd, 5)
		if err != nil {
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("encrypting password: %v", err)
		}
		usr.Password = string(encryptedPwd)

		users[reg] = usr

		s, err := xstrings.ToIndentJSON(users)
		if err != nil {
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("indenting login: %v", err)
		}
		ioutil.WriteFile(config.HyperclairConfig(), s, os.ModePerm)
		client := httpclient.Get()
		req, err := http.NewRequest("GET", HyperclairURI+"/login?realm="+reg, nil)
		if err != nil {
			fmt.Println(xerrors.InternalError)
			logrus.Fatalf("creating login request: %v", err)
		}
		req.SetBasicAuth(usr.Username, string(pwd))

		resp, err := client.Do(req)
		if err != nil || (resp.StatusCode != http.StatusUnauthorized && resp.StatusCode != http.StatusOK) {
Example #4
0
		imageName := strings.Replace(analyses.ImageName, "/", "-", -1) + "-" + analyses.Tag
		switch clair.Report.Format {
		case "html":
			html, err := clair.ReportAsHTML(analyses)
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("generating HTML report: %v", err)
			}
			err = saveReport(imageName, string(html))
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("saving HTML report: %v", err)
			}

		case "json":
			json, err := xstrings.ToIndentJSON(analyses)

			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("indenting JSON: %v", err)
			}
			err = saveReport(imageName, string(json))
			if err != nil {
				fmt.Println(xerrors.InternalError)
				logrus.Fatalf("saving JSON report: %v", err)
			}

		default:
			fmt.Printf("Unsupported Report format: %v", clair.Report.Format)
			logrus.Fatalf("Unsupported Report format: %v", clair.Report.Format)
		}