Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd743f7

Browse files
committed
feat: agentapi uses appearance.Fetcher
1 parent5ad6f3f commitcd743f7

File tree

10 files changed

+57
-34
lines changed

10 files changed

+57
-34
lines changed

‎agent/proto/convert.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,19 @@ func SDKAppFromProto(protoApp *WorkspaceApp) (codersdk.WorkspaceApp, error) {
104104
Health:health,
105105
},nil
106106
}
107+
108+
funcSDKServiceBannerFromProto(sbp*ServiceBanner) codersdk.ServiceBannerConfig {
109+
return codersdk.ServiceBannerConfig{
110+
Enabled:sbp.GetEnabled(),
111+
Message:sbp.GetMessage(),
112+
BackgroundColor:sbp.GetBackgroundColor(),
113+
}
114+
}
115+
116+
funcServiceBannerFromSDK(sb codersdk.ServiceBannerConfig)*ServiceBanner {
117+
return&ServiceBanner{
118+
Enabled:sb.Enabled,
119+
Message:sb.Message,
120+
BackgroundColor:sb.BackgroundColor,
121+
}
122+
}

‎coderd/agentapi/api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
"cdr.dev/slog"
1919
agentproto"github.com/coder/coder/v2/agent/proto"
20+
"github.com/coder/coder/v2/coderd/appearance"
2021
"github.com/coder/coder/v2/coderd/batchstats"
2122
"github.com/coder/coder/v2/coderd/database"
2223
"github.com/coder/coder/v2/coderd/database/pubsub"
@@ -61,6 +62,7 @@ type Options struct {
6162
DerpMapFnfunc()*tailcfg.DERPMap
6263
TailnetCoordinator*atomic.Pointer[tailnet.Coordinator]
6364
TemplateScheduleStore*atomic.Pointer[schedule.TemplateScheduleStore]
65+
AppearanceFetcher*atomic.Pointer[appearance.Fetcher]
6466
StatsBatcher*batchstats.Batcher
6567
PublishWorkspaceUpdateFnfunc(ctx context.Context,workspaceID uuid.UUID)
6668
PublishWorkspaceAgentLogsUpdateFnfunc(ctx context.Context,workspaceAgentID uuid.UUID,msg agentsdk.LogsNotifyMessage)
@@ -104,7 +106,7 @@ func New(opts Options) *API {
104106
}
105107

106108
api.ServiceBannerAPI=&ServiceBannerAPI{
107-
Database:opts.Database,
109+
appearanceFetcher:opts.AppearanceFetcher,
108110
}
109111

110112
api.StatsAPI=&StatsAPI{

‎coderd/agentapi/servicebanner.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,22 @@ package agentapi
22

33
import (
44
"context"
5-
"database/sql"
6-
"encoding/json"
5+
"sync/atomic"
76

87
"golang.org/x/xerrors"
98

10-
agentproto"github.com/coder/coder/v2/agent/proto"
11-
"github.com/coder/coder/v2/coderd/database"
12-
"github.com/coder/coder/v2/codersdk"
9+
"github.com/coder/coder/v2/agent/proto"
10+
"github.com/coder/coder/v2/coderd/appearance"
1311
)
1412

1513
typeServiceBannerAPIstruct {
16-
Database database.Store
14+
appearanceFetcher*atomic.Pointer[appearance.Fetcher]
1715
}
1816

19-
func (a*ServiceBannerAPI)GetServiceBanner(ctx context.Context,_*agentproto.GetServiceBannerRequest) (*agentproto.ServiceBanner,error) {
20-
serviceBannerJSON,err:=a.Database.GetServiceBanner(ctx)
21-
iferr!=nil&&!xerrors.Is(err,sql.ErrNoRows){
22-
returnnil,xerrors.Errorf("get service banner: %w",err)
17+
func (a*ServiceBannerAPI)GetServiceBanner(ctx context.Context,_*proto.GetServiceBannerRequest) (*proto.ServiceBanner,error) {
18+
cfg,err:=(*a.appearanceFetcher.Load()).Fetch(ctx)
19+
iferr!=nil {
20+
returnnil,xerrors.Errorf("fetch appearance: %w",err)
2321
}
24-
25-
varcfg codersdk.ServiceBannerConfig
26-
ifserviceBannerJSON!="" {
27-
err=json.Unmarshal([]byte(serviceBannerJSON),&cfg)
28-
iferr!=nil {
29-
returnnil,xerrors.Errorf("unmarshal json: %w, raw: %s",err,serviceBannerJSON)
30-
}
31-
}
32-
33-
return&agentproto.ServiceBanner{
34-
Enabled:cfg.Enabled,
35-
Message:cfg.Message,
36-
BackgroundColor:cfg.BackgroundColor,
37-
},nil
22+
returnproto.ServiceBannerFromSDK(cfg.ServiceBanner),nil
3823
}

‎coderd/appearance/appearance.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/coder/coder/v2/codersdk"
77
)
88

9-
typeAppearanceFetcherinterface {
9+
typeFetcherinterface {
1010
Fetch(ctx context.Context) (codersdk.AppearanceConfig,error)
1111
}
1212

@@ -28,12 +28,12 @@ var DefaultSupportLinks = []codersdk.LinkConfig{
2828
},
2929
}
3030

31-
typeAGPLAppearancestruct{}
31+
typeAGPLstruct{}
3232

33-
func (AGPLAppearance)Fetch(context.Context) (codersdk.AppearanceConfig,error) {
33+
func (AGPL)Fetch(context.Context) (codersdk.AppearanceConfig,error) {
3434
return codersdk.AppearanceConfig{
3535
SupportLinks:DefaultSupportLinks,
3636
},nil
3737
}
3838

39-
varDefaultAppearanceFetcherAppearanceFetcher=AGPLAppearance{}
39+
varDefaultFetcherFetcher=AGPL{}

‎coderd/coderd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ func New(options *Options) *API {
521521
DisablePathApps:options.DeploymentValues.DisablePathApps.Value(),
522522
SecureAuthCookie:options.DeploymentValues.SecureAuthCookie.Value(),
523523
}
524-
api.AppearanceFetcher.Store(&appearance.DefaultAppearanceFetcher)
524+
api.AppearanceFetcher.Store(&appearance.DefaultFetcher)
525525
api.SiteHandler.AppearanceFetcher=&api.AppearanceFetcher
526526

527527
apiKeyMiddleware:=httpmw.ExtractAPIKeyMW(httpmw.ExtractAPIKeyConfig{
@@ -1087,7 +1087,7 @@ type API struct {
10871087
TailnetCoordinator atomic.Pointer[tailnet.Coordinator]
10881088
TailnetClientService*tailnet.ClientService
10891089
QuotaCommitter atomic.Pointer[proto.QuotaCommitter]
1090-
AppearanceFetcher atomic.Pointer[appearance.AppearanceFetcher]
1090+
AppearanceFetcher atomic.Pointer[appearance.Fetcher]
10911091
// WorkspaceProxyHostsFn returns the hosts of healthy workspace proxies
10921092
// for header reasons.
10931093
WorkspaceProxyHostsFn atomic.Pointer[func() []string]

‎coderd/workspaceagentsrpc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (api *API) workspaceAgentRPC(rw http.ResponseWriter, r *http.Request) {
130130
DerpMapFn:api.DERPMap,
131131
TailnetCoordinator:&api.TailnetCoordinator,
132132
TemplateScheduleStore:api.TemplateScheduleStore,
133+
AppearanceFetcher:&api.AppearanceFetcher,
133134
StatsBatcher:api.statsBatcher,
134135
PublishWorkspaceUpdateFn:api.publishWorkspaceUpdate,
135136
PublishWorkspaceAgentLogsUpdateFn:api.publishWorkspaceAgentLogsUpdate,

‎enterprise/coderd/appearance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type appearanceFetcher struct {
4444
supportLinks []codersdk.LinkConfig
4545
}
4646

47-
funcnewAppearanceFetcher(store database.Store,links []codersdk.LinkConfig) agpl.AppearanceFetcher {
47+
funcnewAppearanceFetcher(store database.Store,links []codersdk.LinkConfig) agpl.Fetcher {
4848
return&appearanceFetcher{
4949
database:store,
5050
supportLinks:links,

‎enterprise/coderd/appearance_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111

12+
"github.com/coder/coder/v2/agent/proto"
1213
"github.com/coder/coder/v2/cli/clibase"
1314
"github.com/coder/coder/v2/coderd/appearance"
1415
"github.com/coder/coder/v2/coderd/coderdtest"
@@ -159,6 +160,8 @@ func TestServiceBanners(t *testing.T) {
159160
banner,err:=agentClient.GetServiceBanner(ctx)
160161
require.NoError(t,err)
161162
require.Equal(t,cfg.ServiceBanner,banner)
163+
banner=requireGetServiceBannerV2(ctx,t,agentClient)
164+
require.Equal(t,cfg.ServiceBanner,banner)
162165

163166
// Create an AGPL Coderd against the same database
164167
agplClient:=coderdtest.New(t,&coderdtest.Options{Database:store,Pubsub:ps})
@@ -167,16 +170,32 @@ func TestServiceBanners(t *testing.T) {
167170
banner,err=agplAgentClient.GetServiceBanner(ctx)
168171
require.NoError(t,err)
169172
require.Equal(t, codersdk.ServiceBannerConfig{},banner)
173+
banner=requireGetServiceBannerV2(ctx,t,agplAgentClient)
174+
require.Equal(t, codersdk.ServiceBannerConfig{},banner)
170175

171176
// No license means no banner.
172177
err=client.DeleteLicense(ctx,lic.ID)
173178
require.NoError(t,err)
174179
banner,err=agentClient.GetServiceBanner(ctx)
175180
require.NoError(t,err)
176181
require.Equal(t, codersdk.ServiceBannerConfig{},banner)
182+
banner=requireGetServiceBannerV2(ctx,t,agentClient)
183+
require.Equal(t, codersdk.ServiceBannerConfig{},banner)
177184
})
178185
}
179186

187+
funcrequireGetServiceBannerV2(ctx context.Context,t*testing.T,client*agentsdk.Client) codersdk.ServiceBannerConfig {
188+
cc,err:=client.Listen(ctx)
189+
require.NoError(t,err)
190+
deferfunc() {
191+
_=cc.Close()
192+
}()
193+
aAPI:=proto.NewDRPCAgentClient(cc)
194+
sbp,err:=aAPI.GetServiceBanner(ctx,&proto.GetServiceBannerRequest{})
195+
require.NoError(t,err)
196+
returnproto.SDKServiceBannerFromProto(sbp)
197+
}
198+
180199
funcTestCustomSupportLinks(t*testing.T) {
181200
t.Parallel()
182201

‎enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
686686
)
687687
api.AGPL.AppearanceFetcher.Store(&f)
688688
}else {
689-
api.AGPL.AppearanceFetcher.Store(&appearance.DefaultAppearanceFetcher)
689+
api.AGPL.AppearanceFetcher.Store(&appearance.DefaultFetcher)
690690
}
691691
}
692692

‎site/site.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ type Handler struct {
148148

149149
buildInfoJSONstring
150150

151-
AppearanceFetcher*atomic.Pointer[appearance.AppearanceFetcher]
151+
AppearanceFetcher*atomic.Pointer[appearance.Fetcher]
152152
// RegionsFetcher will attempt to fetch the more detailed WorkspaceProxy data, but will fall back to the
153153
// regions if the user does not have the correct permissions.
154154
RegionsFetcherfunc(ctx context.Context) (any,error)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp