// checkResp wraps an HTTP request from the default client and verifies that the
// request was successful. A non-200 request returns an error formatted to
// included any validation problems or otherwise.
766859
func checkResp(resp *http.Response, err error) (*http.Response, error) {
	// If the err is already there, there was an error higher up the chain, so
	// just return that.
	if err != nil {
		return resp, err
	}

	switch resp.StatusCode {
	case 200, 201, 202, 204, 205, 206:
		return resp, nil
	default:
		return resp, NewHTTPError(resp)
	}
}
593787
func checkURL(url string) error {
	resp, err := http.Get(url)
	glog.Infof("%s response: %v %+v", url, err, resp)
	if err != nil {
		return errors.Wrap(err, "checkURL")
	}
	if resp.StatusCode != http.StatusOK {
		return &util.RetriableError{
			Err: fmt.Errorf("unexpected response code: %d", resp.StatusCode),
		}
	}
	return nil
}
1080376
func (m *testRPC) CheckValidity(req *Request, secret string) bool {
	if mock := m.currentMocks(nil); mock != nil && mock.DestroyRPCClientMock != nil {
		return mock.CheckValidityMock(req, secret)
	}
	return false
}
1231250
func (b *permBiz) Check(user web.User, scope string, resType, resID string) (err error) {
	au := user.(*model.AuthUser)
	if au.Admin() {
		return
	}

	do(func(d dao.Interface) {
		var perm *model.Perm
		perm, err = d.PermGet(resType, resID)
		if err != nil {
			return
		}

		if perm == nil || perm.Scope == model.PermNone || (scope == "read" && perm.Scope == model.PermWrite) {
			return
		}

		for _, u := range perm.Users {
			if user.ID() == u {
				return
			}
		}

		for _, r := range perm.Roles {
			if au.IsInRole(r) {
				return
			}
		}
		err = ErrForbidden
	})
	return
}
411277
func (hc *HTTPChecker) Check(timeout time.Duration) *Result {
	msg := fmt.Sprintf("HTTP %s to %s", hc.Method, hc.addr())
	start := time.Now()
	if timeout == time.Duration(0) {
		timeout = defaultHTTPTimeout
	}
	deadline := start.Add(timeout)

	u, err := url.Parse(hc.Request)
	if err != nil {
		return complete(start, "", false, err)
	}
	if hc.Secure {
		u.Scheme = "https"
	} else {
		u.Scheme = "http"
	}
	if u.Host == "" {
		u.Host = hc.IP.String()
	}

	proxy := (func(*http.Request) (*url.URL, error))(nil)
	if hc.Proxy {
		proxy = http.ProxyURL(u)
	}

	conn, err := dialTCP(hc.network(), hc.addr(), timeout, hc.Mark)
	if err != nil {
		return complete(start, "", false, err)
	}
	defer conn.Close()

	dialer := func(net string, addr string) (net.Conn, error) {
		return conn, nil
	}
	tlsConfig := &tls.Config{
		InsecureSkipVerify: !hc.TLSVerify,
	}
	client := &http.Client{
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			return errors.New("redirect not permitted")
		},
		Transport: &http.Transport{
			Dial:            dialer,
			Proxy:           proxy,
			TLSClientConfig: tlsConfig,
		},
	}
	req, err := http.NewRequest(hc.Method, hc.Request, nil)
	req.URL = u

	// If we received a response we want to process it, even in the
	// presence of an error - a redirect 3xx will result in both the
	// response and an error being returned.
	conn.SetDeadline(deadline)
	resp, err := client.Do(req)
	if resp == nil {
		return complete(start, "", false, err)
	}
	if resp.Body != nil {
		defer resp.Body.Close()
	}
	err = nil

	// Check response code.
	var codeOk bool
	if hc.ResponseCode == 0 {
		codeOk = true
	} else if resp.StatusCode == hc.ResponseCode {
		codeOk = true
	}

	// Check response body.
	var bodyOk bool
	msg = fmt.Sprintf("%s; got %s", msg, resp.Status)
	if hc.Response == "" {
		bodyOk = true
	} else if resp.Body != nil {
		buf := make([]byte, len(hc.Response))
		n, err := io.ReadFull(resp.Body, buf)
		if err != nil && err != io.ErrUnexpectedEOF {
			msg = fmt.Sprintf("%s; failed to read HTTP response", msg)
		} else if string(buf) != hc.Response {
			msg = fmt.Sprintf("%s; unexpected response - %q", msg, string(buf[0:n]))
		} else {
			bodyOk = true
		}
	}

	return complete(start, msg, codeOk && bodyOk, err)
}
846613
func checkResponseCode(r *http.Response) error {
	if r.StatusCode >= 200 && r.StatusCode < 300 {
		return nil
	}

	rErr := &apitypes.Error{Type: apitypes.LookupErrorType(r.StatusCode)}
	if r.ContentLength != 0 {
		dec := json.NewDecoder(r.Body)
		err := dec.Decode(rErr)
		if err != nil {
			return errBadResponse
		}

		return rErr
	}

	return fmt.Errorf("unknown error response from server with status code %d",
		r.StatusCode)
}
531188
func (c *FakeCSRF) Check(req *http.Request, value string) bool {
	return c.Token == value
}
135855
func (u *user) check(ca checkArg) {
	var err error

	defer func() {
		u.ca.log.Debug("Check %s, err: %v", ca, err)
		ca.retCh <- err
	}()

	if err = u.repopulate(); err != nil {
		return
	}

	if !ca.loadDeleted && u.isDeleted {
		err = ErrUserDeleted
		return
	}

	if ca.username != nil {
		if err = u.checkUsername(*ca.username); err != nil {
			return
		}
	}

	if ca.kid != nil {
		if err = u.checkKey(*ca.kid); err != nil {
			return
		}
	}

	if ca.sibkeys != nil {
		if err = u.compareSibkeys(ca.sibkeys); err != nil {
			return
		}
	}

	if ca.subkeys != nil {
		if err = u.compareSubkeys(ca.subkeys); err != nil {
			return
		}
	}
}
1336341
func (r SSOLoginConsoleReq) Check() error {
	if r.RedirectURL == "" {
		return trace.BadParameter("missing RedirectURL")
	}
	if len(r.PublicKey) == 0 {
		return trace.BadParameter("missing PublicKey")
	}
	if r.ConnectorID == "" {
		return trace.BadParameter("missing ConnectorID")
	}
	return nil
}
1039558
func (v *Validator) CheckSemVer() (errs error) {
	logrus.Debugf("check semver")

	version := v.spec.Version
	_, err := semver.Parse(version)
	if err != nil {
		errs = multierror.Append(errs,
			specerror.NewError(specerror.SpecVersionInSemVer, fmt.Errorf("%q is not valid SemVer: %s", version, err.Error()), rspec.Version))
	}
	if version != rspec.Version {
		errs = multierror.Append(errs, fmt.Errorf("validate currently only handles version %s, but the supplied configuration targets %s", rspec.Version, version))
	}

	return
}
409055
func (m *MockRPCServer) CheckValidity(req *rpcwrapper.Request, secret string) bool {
	ret := m.ctrl.Call(m, "CheckValidity", req, secret)
	ret0, _ := ret[0].(bool)
	return ret0
}
234655
func Check(conn *grpc.ClientConn) (bool, error) {
	res, err := healthpb.NewHealthClient(conn).Check(context.Background(), &healthpb.HealthCheckRequest{})
	if err != nil {
		return false, err
	}
	return res.Status == healthpb.HealthCheckResponse_SERVING, nil
}
882679
func (ex extensions) Check(ext pkix.Extension, d *certdata.Data) *errors.Errors {
	var e = errors.New(nil)
	var found bool

	for _, ec := range ex {
		if ec.oid.Equal(ext.Id) {
			found = true
			if ec.filter != nil && ec.filter.Check(d) {
				continue
			}
			e.Append(ec.f(ext, d))
		}
	}

	if !found {
		// Don't report private enterprise extensions as unknown, registered private
		// extensions have still been checked above.
		if !strings.HasPrefix(ext.Id.String(), "1.3.6.1.4.1.") {
			e.Warning("Certificate contains unknown extension (%s)", ext.Id.String())
		}
	}

	return e
}
156684
func (f *FollowersService) Check(uri *Hyperlink, uriParams M) (success bool, result *Result) {
	url, err := ExpandWithDefault(uri, &CurrentFollowingUrl, uriParams)
	if err != nil {
		return false, &Result{Err: err}
	}

	result = f.client.get(url, nil)
	success = (result.Response.StatusCode == 204)
	return
}
34814
func Check(d *certdata.Data) *errors.Errors {
	var e = errors.New(nil)

	if d.Cert.Version != 3 {
		e.Err("Certificate is not V3 (%d)", d.Cert.Version)
		return e
	}

	return nil
}
1257436
func CheckURL(s string) (string, error) {
	u, err := url.Parse(s)
	if err != nil {
		return "", err
	}
	if u.Scheme == "" {
		s = "https://" + s
		u.Scheme = "https"
	}
	if u.Scheme != "https" && u.Scheme != "http" {
		return "", errors.New("Only http:// or https:// scheme is accepted.")
	}
	if u.Scheme != "https" && hostRequiresSSL(u.Host) {
		return "", errors.New("only https:// scheme is accepted for appspot hosts, it can be omitted")
	}
	if _, err = url.Parse(s); err != nil {
		return "", err
	}
	return s, nil
}
1069120
func checkForErrors(res *http.Response) error {
	if res.StatusCode >= 200 && res.StatusCode < 400 {
		return nil
	}
	defer res.Body.Close()

	out, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return unknownServerError(res.StatusCode, err.Error())
	}

	switch res.StatusCode {
	case 400:
		bodyMap := make(map[string]interface{})
		if err := json.Unmarshal(out, &bodyMap); err != nil {
			return unknownServerError(res.StatusCode, fmt.Sprintf(jsonParsingError, err, string(out)))
		}

		if scanResponse(bodyMap, "username", []string{fieldReqMsg, invalidUserMsg}, true) {
			return ErrInvalidUsername
		}

		if scanResponse(bodyMap, "username", []string{duplicateUserMsg}, true) {
			return ErrDuplicateUsername
		}

		if scanResponse(bodyMap, "password", []string{fieldReqMsg}, true) {
			return ErrMissingPassword
		}

		if scanResponse(bodyMap, "non_field_errors", []string{failedLoginMsg}, true) {
			return ErrLogin
		}

		if scanResponse(bodyMap, "id", []string{invalidAppNameMsg}, true) {
			return ErrInvalidAppName
		}

		if scanResponse(bodyMap, "id", []string{duplicateIDMsg}, true) {
			return ErrDuplicateApp
		}

		if scanResponse(bodyMap, "key", []string{fieldReqMsg}, true) {
			return ErrMissingKey
		}

		if scanResponse(bodyMap, "key", []string{duplicateKeyMsg}, true) {
			return ErrDuplicateKey
		}

		if scanResponse(bodyMap, "public", []string{fieldReqMsg, invalidKeyMsg}, true) {
			return ErrMissingKey
		}

		if scanResponse(bodyMap, "certificate", []string{fieldReqMsg, invalidCertMsg}, false) {
			return ErrInvalidCertificate
		}

		if scanResponse(bodyMap, "name", []string{fieldReqMsg, invalidNameMsg}, true) {
			return ErrInvalidName
		}

		if scanResponse(bodyMap, "domain", []string{invalidDomainMsg}, true) {
			return ErrInvalidDomain
		}

		if scanResponse(bodyMap, "domain", []string{duplicateDomainMsg}, true) {
			return ErrDuplicateDomain
		}

		if scanResponse(bodyMap, "image", []string{fieldReqMsg}, true) {
			return ErrInvalidImage
		}

		if scanResponse(bodyMap, "id", []string{fieldReqMsg}, true) {
			return ErrMissingID
		}

		if scanResponse(bodyMap, "email", []string{invalidEmailMsg}, true) {
			return ErrInvalidEmail
		}

		if v, ok := bodyMap["detail"].(string); ok {
			if strings.Contains(v, invalidPodMsg) {
				return ErrPodNotFound
			}
			if strings.Contains(v, invalidVersionMsg) {
				return ErrInvalidVersion
			}
			if strings.Contains(v, invalidTagMsg) {
				return ErrTagNotFound
			}
		}
		return unknownServerError(res.StatusCode, string(out))
	case 401:
		return ErrUnauthorized
	case 403:
		return ErrForbidden
	case 404:
		if string(out) != "" {
			return ErrNotFound{string(out)}
		}
		return ErrNotFound{"Not Found"}
	case 405:
		return ErrMethodNotAllowed
	case 409:
		bodyMap := make(map[string]interface{})
		if err := json.Unmarshal(out, &bodyMap); err != nil {
			return unknownServerError(res.StatusCode, fmt.Sprintf(jsonParsingError, err, string(out)))
		}
		if v, ok := bodyMap["detail"].(string); ok {
			if strings.Contains(v, cancellationFailedMsg) {
				return ErrCancellationFailed
			}
		}
		return unknownServerError(res.StatusCode, string(out))
	case 422:
		bodyMap := make(map[string]interface{})
		if err := json.Unmarshal(out, &bodyMap); err != nil {
			return unknownServerError(res.StatusCode, fmt.Sprintf(jsonParsingError, err, string(out)))
		}
		if v, ok := bodyMap["detail"].(string); ok {
			return ErrUnprocessable{v}
		}
		return unknownServerError(res.StatusCode, string(out))
	case 500:
		return ErrServerError
	default:
		return unknownServerError(res.StatusCode, string(out))
	}
}