// NewGithubStatusMessageWithRepo creates a composer for sending payloads to the Github Status
// API, with the repository and ref stored in the composer
185403
func NewGithubStatusMessageWithRepo(p level.Priority, status GithubStatus) Composer {
	s := MakeGithubStatusMessageWithRepo(status)
	_ = s.SetPriority(p)

	return s
}
1043902
func NewStatusStrategy(typer runtime.ObjectTyper) rest.RESTUpdateStrategy {
	return apiServerStatusStrategy{typer, names.SimpleNameGenerator}
}
624484
func NewRepo(origin Remote, opts ...Option) *Repo {
	status := RepoNew
	if origin.URL == "" {
		status = RepoNoConfig
	}
	r := &Repo{
		origin:   origin,
		status:   status,
		interval: defaultInterval,
		timeout:  defaultTimeout,
		err:      ErrNotCloned,
		notify:   make(chan struct{}, 1), // `1` so that Notify doesn't block
		C:        make(chan struct{}, 1), // `1` so we don't block on completing a refresh
	}
	for _, opt := range opts {
		opt.apply(r)
	}
	return r
}
685301
func NewMessage() *Message {
	return &Message{
		payload: lane.NewStack(),
		Reports: lane.NewStack(),
		Opts:    cmap.New(),
	}
}
738664
func (s *AuthServer) validateGithubAuthCallback(q url.Values) (*GithubAuthResponse, error) {
	logger := log.WithFields(logrus.Fields{trace.Component: "github"})
	error := q.Get("error")
	if error != "" {
		return nil, trace.OAuth2(oauth2.ErrorInvalidRequest, error, q)
	}
	code := q.Get("code")
	if code == "" {
		return nil, trace.OAuth2(oauth2.ErrorInvalidRequest,
			"code query param must be set", q)
	}
	stateToken := q.Get("state")
	if stateToken == "" {
		return nil, trace.OAuth2(oauth2.ErrorInvalidRequest,
			"missing state query param", q)
	}
	req, err := s.Identity.GetGithubAuthRequest(stateToken)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	connector, err := s.Identity.GetGithubConnector(req.ConnectorID, true)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	if len(connector.GetTeamsToLogins()) == 0 {
		logger.Warnf("Github connector %q has empty teams_to_logins mapping, cannot populate claims.",
			connector.GetName())
		return nil, trace.BadParameter(
			"connector %q has empty teams_to_logins mapping", connector.GetName())
	}
	client, err := s.getGithubOAuth2Client(connector)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	// exchange the authorization code received by the callback for an access token
	token, err := client.RequestToken(oauth2.GrantTypeAuthCode, code)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	logger.Debugf("Obtained OAuth2 token: Type=%v Expires=%v Scope=%v.",
		token.TokenType, token.Expires, token.Scope)
	// Github does not support OIDC so user claims have to be populated
	// by making requests to Github API using the access token
	claims, err := populateGithubClaims(&githubAPIClient{
		token:      token.AccessToken,
		authServer: s,
	})
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// Calculate (figure out name, roles, traits, session TTL) of user and
	// create the user in the backend.
	params, err := s.calculateGithubUser(connector, claims, req)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	user, err := s.createGithubUser(params)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// Auth was successful, return session, certificate, etc. to caller.
	response := &GithubAuthResponse{
		Req: *req,
		Identity: services.ExternalIdentity{
			ConnectorID: params.connectorName,
			Username:    params.username,
		},
		Username: user.GetName(),
	}
	response.Username = user.GetName()

	// If the request is coming from a browser, create a web session.
	if req.CreateWebSession {
		session, err := s.createWebSession(user, params.sessionTTL)
		if err != nil {
			return nil, trace.Wrap(err)
		}

		response.Session = session
	}

	// If a public key was provided, sign it and return a certificate.
	if len(req.PublicKey) != 0 {
		sshCert, tlsCert, err := s.createSessionCert(user, params.sessionTTL, req.PublicKey, req.Compatibility)
		if err != nil {
			return nil, trace.Wrap(err)
		}

		clusterName, err := s.GetClusterName()
		if err != nil {
			return nil, trace.Wrap(err)
		}

		response.Cert = sshCert
		response.TLSCert = tlsCert

		// Return the host CA for this cluster only.
		authority, err := s.GetCertAuthority(services.CertAuthID{
			Type:       services.HostCA,
			DomainName: clusterName.GetClusterName(),
		}, false)
		if err != nil {
			return nil, trace.Wrap(err)
		}
		response.HostSigners = append(response.HostSigners, authority)
	}

	return response, nil
}
666741
func (s *CodeDestination) SetGitHub(v *GitHubCodeDestination) *CodeDestination {
	s.GitHub = v
	return s
}
1183285
func NewGithubProvider(clientId, clientSecret, scope string) *GithubProvider {
	github := GithubProvider{}
	github.AuthorizationURL = "https://github.com/login/oauth/authorize"
	github.AccessTokenURL   = "https://github.com/login/oauth/access_token"
	github.ClientId         = clientId
	github.ClientSecret     = clientSecret
	github.Scope            = scope

	// default the Scope if not provided
	if len(github.Scope) == 0 {
		github.Scope = "user:email"
	}
	return &github
}
460588
func NewMessagesReceivedTotalStatsHandler(sub Subsystem, vec *prometheus.CounterVec) *MessagesReceivedTotalStatsHandler {
	return &MessagesReceivedTotalStatsHandler{
		baseStatsHandler: baseStatsHandler{
			subsystem: sub,
			collector: vec,
		},
		vec: vec,
	}
}
415807
func (s *AuthServer) CreateGithubAuthRequest(req services.GithubAuthRequest) (*services.GithubAuthRequest, error) {
	connector, err := s.Identity.GetGithubConnector(req.ConnectorID, true)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	client, err := s.getGithubOAuth2Client(connector)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	req.StateToken, err = utils.CryptoRandomHex(TokenLenBytes)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	req.RedirectURL = client.AuthCodeURL(req.StateToken, "", "")
	log.WithFields(logrus.Fields{trace.Component: "github"}).Debugf(
		"Redirect URL: %v.", req.RedirectURL)
	req.SetTTL(s.GetClock(), defaults.GithubAuthRequestTTL)
	err = s.Identity.CreateGithubAuthRequest(req)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	return &req, nil
}
734004
func SendCollaboratorMail(u, doer User, repo Repository) {
	subject := fmt.Sprintf("%s added you to %s", doer.DisplayName(), repo.FullName())

	data := map[string]interface{}{
		"Subject":  subject,
		"RepoName": repo.FullName(),
		"Link":     repo.HTMLURL(),
	}
	body, err := mailRender.HTMLString(string(MAIL_NOTIFY_COLLABORATOR), data)
	if err != nil {
		log.Error(3, "HTMLString: %v", err)
		return
	}

	msg := NewMessage([]string{u.Email()}, subject, body)
	msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID())

	Send(msg)
}
709850
func (fw *Framework) NewReplyFromMessage(version string, msg *Message) (rep protocol.Reply, err error) {
	if msg.Type() != "reply" {
		err = fmt.Errorf("Cannot use `%s` message to construct a Reply", msg.Type())
		return
	}

	if msg.Request == nil {
		err = fmt.Errorf("Cannot create a Reply from Messages without Requests")
		return
	}

	req, err := fw.NewRequestFromMessage(version, msg.Request)
	if err != nil {
		return
	}

	rep, err = fw.NewReply(req)
	rep.SetMessage(msg.Payload)

	return
}
391711
func (conn *BytesManualConnectionStr) NewAsyncPublisherToPartition(topic string, partition int32, successClb func(*client.ProducerMessage), errorClb func(err *client.ProducerError)) (BytesPublisher, error) {
	return &bytesManualAsyncPublisherKafka{conn, topic, partition, successClb, errorClb}, nil
}
386812
func MakeJIRACommentMessage(issueID, body string) Composer {
	return &jiraComment{
		Payload: JIRAComment{
			IssueID: issueID,
			Body:    body,
		},
	}
}
898138
func (c *ServiceWorker) DeliverPushMessageWithParams(v *ServiceWorkerDeliverPushMessageParams) (*gcdmessage.ChromeResponse, error) {
	return gcdmessage.SendDefaultRequest(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "ServiceWorker.deliverPushMessage", Params: v})
}
1156283
func (s *ReplicationJob) SetStatusMessage(v string) *ReplicationJob {
	s.StatusMessage = &v
	return s
}
637986
func (s *MatchmakingTicket) SetStatusMessage(v string) *MatchmakingTicket {
	s.StatusMessage = &v
	return s
}
620960
func NewGithubStatusMessage(p level.Priority, context string, state GithubState, URL, description string) Composer {
	s := MakeGithubStatusMessage(context, state, URL, description)
	_ = s.SetPriority(p)

	return s
}