forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannouncement_banners.go
More file actions
39 lines (33 loc) · 1.28 KB
/
Copy pathannouncement_banners.go
File metadata and controls
39 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package agentapi
import (
"context"
"sync/atomic"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/agent/proto"
"github.com/coder/coder/v2/coderd/appearance"
"github.com/coder/coder/v2/codersdk/agentsdk"
)
type AnnouncementBannerAPI struct {
appearanceFetcher *atomic.Pointer[appearance.Fetcher]
}
// Deprecated: GetServiceBanner has been deprecated in favor of GetAnnouncementBanners.
func (a *AnnouncementBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetServiceBannerRequest) (*proto.ServiceBanner, error) {
cfg, err := (*a.appearanceFetcher.Load()).Fetch(ctx)
if err != nil {
return nil, xerrors.Errorf("fetch appearance: %w", err)
}
return agentsdk.ProtoFromServiceBanner(cfg.ServiceBanner), nil
}
func (a *AnnouncementBannerAPI) GetAnnouncementBanners(ctx context.Context, _ *proto.GetAnnouncementBannersRequest) (*proto.GetAnnouncementBannersResponse, error) {
cfg, err := (*a.appearanceFetcher.Load()).Fetch(ctx)
if err != nil {
return nil, xerrors.Errorf("fetch appearance: %w", err)
}
banners := make([]*proto.BannerConfig, 0, len(cfg.AnnouncementBanners))
for _, banner := range cfg.AnnouncementBanners {
banners = append(banners, agentsdk.ProtoFromBannerConfig(banner))
}
return &proto.GetAnnouncementBannersResponse{
AnnouncementBanners: banners,
}, nil
}