Skip to content

Commit b248f12

Browse files
authored
chore: rename notification banners to announcement banners (#13419)
1 parent de8149f commit b248f12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+355
-349
lines changed

agent/agent.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func New(options Options) Agent {
176176
ignorePorts: options.IgnorePorts,
177177
portCacheDuration: options.PortCacheDuration,
178178
reportMetadataInterval: options.ReportMetadataInterval,
179-
notificationBannersRefreshInterval: options.ServiceBannerRefreshInterval,
179+
announcementBannersRefreshInterval: options.ServiceBannerRefreshInterval,
180180
sshMaxTimeout: options.SSHMaxTimeout,
181181
subsystems: options.Subsystems,
182182
addresses: options.Addresses,
@@ -193,7 +193,7 @@ func New(options Options) Agent {
193193
// that gets closed on disconnection. This is used to wait for graceful disconnection from the
194194
// coordinator during shut down.
195195
close(a.coordDisconnected)
196-
a.notificationBanners.Store(new([]codersdk.BannerConfig))
196+
a.announcementBanners.Store(new([]codersdk.BannerConfig))
197197
a.sessionToken.Store(new(string))
198198
a.init()
199199
return a
@@ -234,8 +234,8 @@ type agent struct {
234234
manifest atomic.Pointer[agentsdk.Manifest] // manifest is atomic because values can change after reconnection.
235235
reportMetadataInterval time.Duration
236236
scriptRunner *agentscripts.Runner
237-
notificationBanners atomic.Pointer[[]codersdk.BannerConfig] // notificationBanners is atomic because it is periodically updated.
238-
notificationBannersRefreshInterval time.Duration
237+
announcementBanners atomic.Pointer[[]codersdk.BannerConfig] // announcementBanners is atomic because it is periodically updated.
238+
announcementBannersRefreshInterval time.Duration
239239
sessionToken atomic.Pointer[string]
240240
sshServer *agentssh.Server
241241
sshMaxTimeout time.Duration
@@ -274,7 +274,7 @@ func (a *agent) init() {
274274
sshSrv, err := agentssh.NewServer(a.hardCtx, a.logger.Named("ssh-server"), a.prometheusRegistry, a.filesystem, &agentssh.Config{
275275
MaxTimeout: a.sshMaxTimeout,
276276
MOTDFile: func() string { return a.manifest.Load().MOTDFile },
277-
NotificationBanners: func() *[]codersdk.BannerConfig { return a.notificationBanners.Load() },
277+
AnnouncementBanners: func() *[]codersdk.BannerConfig { return a.announcementBanners.Load() },
278278
UpdateEnv: a.updateCommandEnv,
279279
WorkingDirectory: func() string { return a.manifest.Load().Directory },
280280
})
@@ -709,26 +709,26 @@ func (a *agent) setLifecycle(state codersdk.WorkspaceAgentLifecycle) {
709709
// (and must be done before the session actually starts).
710710
func (a *agent) fetchServiceBannerLoop(ctx context.Context, conn drpc.Conn) error {
711711
aAPI := proto.NewDRPCAgentClient(conn)
712-
ticker := time.NewTicker(a.notificationBannersRefreshInterval)
712+
ticker := time.NewTicker(a.announcementBannersRefreshInterval)
713713
defer ticker.Stop()
714714
for {
715715
select {
716716
case <-ctx.Done():
717717
return ctx.Err()
718718
case <-ticker.C:
719-
bannersProto, err := aAPI.GetNotificationBanners(ctx, &proto.GetNotificationBannersRequest{})
719+
bannersProto, err := aAPI.GetAnnouncementBanners(ctx, &proto.GetAnnouncementBannersRequest{})
720720
if err != nil {
721721
if ctx.Err() != nil {
722722
return ctx.Err()
723723
}
724724
a.logger.Error(ctx, "failed to update notification banners", slog.Error(err))
725725
return err
726726
}
727-
banners := make([]codersdk.BannerConfig, 0, len(bannersProto.NotificationBanners))
728-
for _, bannerProto := range bannersProto.NotificationBanners {
727+
banners := make([]codersdk.BannerConfig, 0, len(bannersProto.AnnouncementBanners))
728+
for _, bannerProto := range bannersProto.AnnouncementBanners {
729729
banners = append(banners, agentsdk.BannerConfigFromProto(bannerProto))
730730
}
731-
a.notificationBanners.Store(&banners)
731+
a.announcementBanners.Store(&banners)
732732
}
733733
}
734734
}
@@ -763,15 +763,15 @@ func (a *agent) run() (retErr error) {
763763
connMan.start("init notification banners", gracefulShutdownBehaviorStop,
764764
func(ctx context.Context, conn drpc.Conn) error {
765765
aAPI := proto.NewDRPCAgentClient(conn)
766-
bannersProto, err := aAPI.GetNotificationBanners(ctx, &proto.GetNotificationBannersRequest{})
766+
bannersProto, err := aAPI.GetAnnouncementBanners(ctx, &proto.GetAnnouncementBannersRequest{})
767767
if err != nil {
768768
return xerrors.Errorf("fetch service banner: %w", err)
769769
}
770-
banners := make([]codersdk.BannerConfig, 0, len(bannersProto.NotificationBanners))
771-
for _, bannerProto := range bannersProto.NotificationBanners {
770+
banners := make([]codersdk.BannerConfig, 0, len(bannersProto.AnnouncementBanners))
771+
for _, bannerProto := range bannersProto.AnnouncementBanners {
772772
banners = append(banners, agentsdk.BannerConfigFromProto(bannerProto))
773773
}
774-
a.notificationBanners.Store(&banners)
774+
a.announcementBanners.Store(&banners)
775775
return nil
776776
},
777777
)

agent/agent_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func TestAgent_Session_TTY_MOTD_Update(t *testing.T) {
614614
// Set new banner func and wait for the agent to call it to update the
615615
// banner.
616616
ready := make(chan struct{}, 2)
617-
client.SetNotificationBannersFunc(func() ([]codersdk.BannerConfig, error) {
617+
client.SetAnnouncementBannersFunc(func() ([]codersdk.BannerConfig, error) {
618618
select {
619619
case ready <- struct{}{}:
620620
default:
@@ -2200,7 +2200,7 @@ func setupSSHSession(
22002200
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
22012201
defer cancel()
22022202
opts = append(opts, func(c *agenttest.Client, o *agent.Options) {
2203-
c.SetNotificationBannersFunc(func() ([]codersdk.BannerConfig, error) {
2203+
c.SetAnnouncementBannersFunc(func() ([]codersdk.BannerConfig, error) {
22042204
return []codersdk.BannerConfig{banner}, nil
22052205
})
22062206
})

agent/agentssh/agentssh.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Config struct {
6363
// file will be displayed to the user upon login.
6464
MOTDFile func() string
6565
// ServiceBanner returns the configuration for the Coder service banner.
66-
NotificationBanners func() *[]codersdk.BannerConfig
66+
AnnouncementBanners func() *[]codersdk.BannerConfig
6767
// UpdateEnv updates the environment variables for the command to be
6868
// executed. It can be used to add, modify or replace environment variables.
6969
UpdateEnv func(current []string) (updated []string, err error)
@@ -123,8 +123,8 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
123123
if config.MOTDFile == nil {
124124
config.MOTDFile = func() string { return "" }
125125
}
126-
if config.NotificationBanners == nil {
127-
config.NotificationBanners = func() *[]codersdk.BannerConfig { return &[]codersdk.BannerConfig{} }
126+
if config.AnnouncementBanners == nil {
127+
config.AnnouncementBanners = func() *[]codersdk.BannerConfig { return &[]codersdk.BannerConfig{} }
128128
}
129129
if config.WorkingDirectory == nil {
130130
config.WorkingDirectory = func() string {
@@ -441,13 +441,13 @@ func (s *Server) startPTYSession(logger slog.Logger, session ptySession, magicTy
441441
session.DisablePTYEmulation()
442442

443443
if isLoginShell(session.RawCommand()) {
444-
banners := s.config.NotificationBanners()
444+
banners := s.config.AnnouncementBanners()
445445
if banners != nil {
446446
for _, banner := range *banners {
447-
err := showNotificationBanner(session, banner)
447+
err := showAnnouncementBanner(session, banner)
448448
if err != nil {
449-
logger.Error(ctx, "agent failed to show service banner", slog.Error(err))
450-
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "notification_banner").Add(1)
449+
logger.Error(ctx, "agent failed to show announcement banner", slog.Error(err))
450+
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, "yes", "announcement_banner").Add(1)
451451
break
452452
}
453453
}
@@ -894,9 +894,9 @@ func isQuietLogin(fs afero.Fs, rawCommand string) bool {
894894
return err == nil
895895
}
896896

897-
// showNotificationBanner will write the service banner if enabled and not blank
897+
// showAnnouncementBanner will write the service banner if enabled and not blank
898898
// along with a blank line for spacing.
899-
func showNotificationBanner(session io.Writer, banner codersdk.BannerConfig) error {
899+
func showAnnouncementBanner(session io.Writer, banner codersdk.BannerConfig) error {
900900
if banner.Enabled && banner.Message != "" {
901901
// The banner supports Markdown so we might want to parse it but Markdown is
902902
// still fairly readable in its raw form.

agent/agenttest/client.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ func (c *Client) GetStartupLogs() []agentsdk.Log {
138138
return c.logs
139139
}
140140

141-
func (c *Client) SetNotificationBannersFunc(f func() ([]codersdk.ServiceBannerConfig, error)) {
142-
c.fakeAgentAPI.SetNotificationBannersFunc(f)
141+
func (c *Client) SetAnnouncementBannersFunc(f func() ([]codersdk.BannerConfig, error)) {
142+
c.fakeAgentAPI.SetAnnouncementBannersFunc(f)
143143
}
144144

145145
func (c *Client) PushDERPMapUpdate(update *tailcfg.DERPMap) error {
@@ -171,7 +171,7 @@ type FakeAgentAPI struct {
171171
lifecycleStates []codersdk.WorkspaceAgentLifecycle
172172
metadata map[string]agentsdk.Metadata
173173

174-
getNotificationBannersFunc func() ([]codersdk.BannerConfig, error)
174+
getAnnouncementBannersFunc func() ([]codersdk.BannerConfig, error)
175175
}
176176

177177
func (f *FakeAgentAPI) GetManifest(context.Context, *agentproto.GetManifestRequest) (*agentproto.Manifest, error) {
@@ -182,28 +182,28 @@ func (*FakeAgentAPI) GetServiceBanner(context.Context, *agentproto.GetServiceBan
182182
return &agentproto.ServiceBanner{}, nil
183183
}
184184

185-
func (f *FakeAgentAPI) SetNotificationBannersFunc(fn func() ([]codersdk.BannerConfig, error)) {
185+
func (f *FakeAgentAPI) SetAnnouncementBannersFunc(fn func() ([]codersdk.BannerConfig, error)) {
186186
f.Lock()
187187
defer f.Unlock()
188-
f.getNotificationBannersFunc = fn
188+
f.getAnnouncementBannersFunc = fn
189189
f.logger.Info(context.Background(), "updated notification banners")
190190
}
191191

192-
func (f *FakeAgentAPI) GetNotificationBanners(context.Context, *agentproto.GetNotificationBannersRequest) (*agentproto.GetNotificationBannersResponse, error) {
192+
func (f *FakeAgentAPI) GetAnnouncementBanners(context.Context, *agentproto.GetAnnouncementBannersRequest) (*agentproto.GetAnnouncementBannersResponse, error) {
193193
f.Lock()
194194
defer f.Unlock()
195-
if f.getNotificationBannersFunc == nil {
196-
return &agentproto.GetNotificationBannersResponse{NotificationBanners: []*agentproto.BannerConfig{}}, nil
195+
if f.getAnnouncementBannersFunc == nil {
196+
return &agentproto.GetAnnouncementBannersResponse{AnnouncementBanners: []*agentproto.BannerConfig{}}, nil
197197
}
198-
banners, err := f.getNotificationBannersFunc()
198+
banners, err := f.getAnnouncementBannersFunc()
199199
if err != nil {
200200
return nil, err
201201
}
202202
bannersProto := make([]*agentproto.BannerConfig, 0, len(banners))
203203
for _, banner := range banners {
204204
bannersProto = append(bannersProto, agentsdk.ProtoFromBannerConfig(banner))
205205
}
206-
return &agentproto.GetNotificationBannersResponse{NotificationBanners: bannersProto}, nil
206+
return &agentproto.GetAnnouncementBannersResponse{AnnouncementBanners: bannersProto}, nil
207207
}
208208

209209
func (f *FakeAgentAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsRequest) (*agentproto.UpdateStatsResponse, error) {

0 commit comments

Comments
 (0)