(ctx context.Context)
| 61 | } |
| 62 | |
| 63 | func (f *appearanceFetcher) Fetch(ctx context.Context) (codersdk.AppearanceConfig, error) { |
| 64 | var eg errgroup.Group |
| 65 | var ( |
| 66 | applicationName string |
| 67 | logoURL string |
| 68 | announcementBannersJSON string |
| 69 | ) |
| 70 | eg.Go(func() (err error) { |
| 71 | applicationName, err = f.database.GetApplicationName(ctx) |
| 72 | if err != nil && !errors.Is(err, sql.ErrNoRows) { |
| 73 | return xerrors.Errorf("get application name: %w", err) |
| 74 | } |
| 75 | return nil |
| 76 | }) |
| 77 | eg.Go(func() (err error) { |
| 78 | logoURL, err = f.database.GetLogoURL(ctx) |
| 79 | if err != nil && !errors.Is(err, sql.ErrNoRows) { |
| 80 | return xerrors.Errorf("get logo url: %w", err) |
| 81 | } |
| 82 | return nil |
| 83 | }) |
| 84 | eg.Go(func() (err error) { |
| 85 | announcementBannersJSON, err = f.database.GetAnnouncementBanners(ctx) |
| 86 | if err != nil && !errors.Is(err, sql.ErrNoRows) { |
| 87 | return xerrors.Errorf("get notification banners: %w", err) |
| 88 | } |
| 89 | return nil |
| 90 | }) |
| 91 | err := eg.Wait() |
| 92 | if err != nil { |
| 93 | return codersdk.AppearanceConfig{}, err |
| 94 | } |
| 95 | |
| 96 | cfg := codersdk.AppearanceConfig{ |
| 97 | ApplicationName: applicationName, |
| 98 | LogoURL: logoURL, |
| 99 | AnnouncementBanners: []codersdk.BannerConfig{}, |
| 100 | SupportLinks: codersdk.DefaultSupportLinks(f.docsURL), |
| 101 | DocsURL: f.docsURL, |
| 102 | } |
| 103 | |
| 104 | if announcementBannersJSON != "" { |
| 105 | err = json.Unmarshal([]byte(announcementBannersJSON), &cfg.AnnouncementBanners) |
| 106 | if err != nil { |
| 107 | return codersdk.AppearanceConfig{}, xerrors.Errorf( |
| 108 | "unmarshal announcement banners json: %w, raw: %s", err, announcementBannersJSON, |
| 109 | ) |
| 110 | } |
| 111 | |
| 112 | // Redundant, but improves compatibility with slightly mismatched agent versions. |
| 113 | // Maybe we can remove this after a grace period? -Kayla, May 6th 2024 |
| 114 | if len(cfg.AnnouncementBanners) > 0 { |
| 115 | cfg.ServiceBanner = cfg.AnnouncementBanners[0] |
| 116 | } |
| 117 | } |
| 118 | if len(f.supportLinks) > 0 { |
| 119 | cfg.SupportLinks = f.supportLinks |
| 120 | } |
nothing calls this directly
no test coverage detected