MCPcopy Index your code
hub / github.com/coder/coder / AppInstallations

Method AppInstallations

coderd/externalauth/externalauth.go:534–581  ·  view source on GitHub ↗

AppInstallations returns a list of app installations for the given token. If the provider does not support app installations, it returns nil.

(ctx context.Context, token string)

Source from the content-addressed store, hash-verified

532// AppInstallations returns a list of app installations for the given token.
533// If the provider does not support app installations, it returns nil.
534func (c *Config) AppInstallations(ctx context.Context, token string) ([]codersdk.ExternalAuthAppInstallation, bool, error) {
535 if c.AppInstallationsURL == "" {
536 return nil, false, nil
537 }
538 req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.AppInstallationsURL, nil)
539 if err != nil {
540 return nil, false, err
541 }
542 req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
543 res, err := c.InstrumentedOAuth2Config.Do(ctx, promoauth.SourceAppInstallations, req)
544 if err != nil {
545 return nil, false, err
546 }
547 defer res.Body.Close()
548 // It's possible the installation URL is misconfigured, so we don't
549 // want to return an error here.
550 if res.StatusCode != http.StatusOK {
551 return nil, false, nil
552 }
553 installs := []codersdk.ExternalAuthAppInstallation{}
554 if c.Type == string(codersdk.EnhancedExternalAuthProviderGitHub) {
555 var ghInstalls struct {
556 Installations []*github.Installation `json:"installations"`
557 }
558 err = json.NewDecoder(res.Body).Decode(&ghInstalls)
559 if err != nil {
560 return nil, false, err
561 }
562 for _, installation := range ghInstalls.Installations {
563 account := installation.GetAccount()
564 if account == nil {
565 continue
566 }
567 installs = append(installs, codersdk.ExternalAuthAppInstallation{
568 ID: int(installation.GetID()),
569 ConfigureURL: installation.GetHTMLURL(),
570 Account: codersdk.ExternalAuthUser{
571 ID: account.GetID(),
572 Login: account.GetLogin(),
573 AvatarURL: account.GetAvatarURL(),
574 ProfileURL: account.GetHTMLURL(),
575 Name: account.GetName(),
576 },
577 })
578 }
579 }
580 return installs, true, nil
581}
582
583func (c *Config) RevokeToken(ctx context.Context, link database.ExternalAuthLink) (bool, error) {
584 if c.RevokeURL == "" {

Callers 1

externalAuthByIDMethod · 0.80

Calls 4

SetMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
GetNameMethod · 0.45

Tested by

no test coverage detected