Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 856e41e

Browse files
fix(appliance): Make Appliance URL envvars strings (#64227)
<!-- PR description tips: https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e --> Changes `APPLIANCE_MANAGED` -> `APPLIANCE_UPDATE_TARGET`, and creates `APPLIANCE_MENU_TARGET`. Both are stringly typed env vars, that when set will create / redirect the update buttons / menu links in the site admin and nav item pages. Paired with @nelsonjr and @DaedalusG on this ## Test plan <!-- REQUIRED; info at https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles --> Manually Tested ## Changelog <!-- OPTIONAL; info at https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c --> - **fix(appliance): make environment variables strings to be passed around**
1 parent aaa464e commit 856e41e

File tree

11 files changed

+42
-32
lines changed

11 files changed

+42
-32
lines changed

client/web/dev/utils/create-js-context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st
3535
accessTokensExpirationDaysOptions: [7, 14, 30, 60, 90],
3636
allowSignup: true,
3737
batchChangesEnabled: true,
38-
applianceManaged: false,
38+
applianceUpdateTarget: '',
39+
applianceMenuTarget: '',
3940
batchChangesDisableWebhooksWarning: false,
4041
batchChangesWebhookLogsEnabled: true,
4142
executorsEnabled: false,

client/web/src/enterprise/site-admin/SiteAdminSidebar.story.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const AdminSidebarItems: StoryFn = () => (
3434
batchChangesExecutionEnabled={true}
3535
batchChangesWebhookLogsEnabled={true}
3636
codeInsightsEnabled={true}
37-
applianceManaged={false}
37+
applianceUpdateTarget=""
3838
endUserOnboardingEnabled={false}
3939
/>
4040
<SiteAdminSidebar
@@ -45,7 +45,7 @@ export const AdminSidebarItems: StoryFn = () => (
4545
batchChangesExecutionEnabled={true}
4646
batchChangesWebhookLogsEnabled={true}
4747
codeInsightsEnabled={true}
48-
applianceManaged={false}
48+
applianceUpdateTarget=""
4949
endUserOnboardingEnabled={false}
5050
/>
5151
<SiteAdminSidebar
@@ -56,7 +56,7 @@ export const AdminSidebarItems: StoryFn = () => (
5656
batchChangesExecutionEnabled={false}
5757
batchChangesWebhookLogsEnabled={false}
5858
codeInsightsEnabled={true}
59-
applianceManaged={false}
59+
applianceUpdateTarget=""
6060
endUserOnboardingEnabled={false}
6161
/>
6262
<SiteAdminSidebar
@@ -67,7 +67,7 @@ export const AdminSidebarItems: StoryFn = () => (
6767
batchChangesExecutionEnabled={true}
6868
batchChangesWebhookLogsEnabled={true}
6969
codeInsightsEnabled={false}
70-
applianceManaged={false}
70+
applianceUpdateTarget=""
7171
endUserOnboardingEnabled={false}
7272
/>
7373
</Grid>

client/web/src/integration/jscontext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export const createJsContext = ({ sourcegraphBaseUrl }: { sourcegraphBaseUrl: st
2727
accessTokensExpirationDaysOptions: [7, 30, 60, 90],
2828
allowSignup: false,
2929
batchChangesEnabled: true,
30-
applianceManaged: false,
30+
applianceUpdateTarget: '',
31+
applianceMenuTarget: '',
3132
batchChangesDisableWebhooksWarning: false,
3233
batchChangesWebhookLogsEnabled: true,
3334
codeInsightsEnabled: true,

client/web/src/jscontext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ export interface SourcegraphContext extends Pick<Required<SiteConfiguration>, 'e
199199
/**
200200
* Whether this sourcegraph instance is managed by Appliance
201201
*/
202-
applianceManaged: boolean
202+
applianceUpdateTarget: string
203+
applianceMenuTarget: string
203204

204205
/**
205206
* Whether Cody is enabled on this instance. Check

client/web/src/nav/UserNavItem.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ export const UserNavItem: FC<UserNavItemProps> = props => {
227227
Site admin
228228
</MenuLink>
229229
)}
230+
{authenticatedUser.siteAdmin && window.context.applianceMenuTarget !== '' && (
231+
<MenuLink as={Link} to={window.context.applianceMenuTarget}>
232+
Appliance
233+
</MenuLink>
234+
)}
230235
<MenuLink as={Link} to="/help" target="_blank" rel="noopener">
231236
Help <Icon aria-hidden={true} svgPath={mdiOpenInNew} />
232237
</MenuLink>

client/web/src/routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export const routes: RouteObject[] = [
299299
sideBarGroups={props.siteAdminSideBarGroups}
300300
overviewComponents={props.siteAdminOverviewComponents}
301301
codeInsightsEnabled={window.context.codeInsightsEnabled}
302-
applianceManaged={window.context.applianceManaged}
302+
applianceUpdateTarget={window.context.applianceUpdateTarget}
303303
telemetryRecorder={props.platformContext.telemetryRecorder}
304304
/>
305305
)}

client/web/src/site-admin/SiteAdminArea.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface SiteAdminAreaRouteContext
5959
overviewComponents: readonly React.ComponentType<React.PropsWithChildren<{}>>[]
6060

6161
codeInsightsEnabled: boolean
62-
applianceManaged: boolean
62+
applianceUpdateTarget: string
6363

6464
endUserOnboardingEnabled: boolean
6565
}
@@ -78,7 +78,7 @@ interface SiteAdminAreaProps
7878
authenticatedUser: AuthenticatedUser
7979
isSourcegraphDotCom: boolean
8080
codeInsightsEnabled: boolean
81-
applianceManaged: boolean
81+
applianceUpdateTarget: string
8282
}
8383

8484
const sourcegraphOperatorSiteAdminMaintenanceBlockItems = new Set([
@@ -144,7 +144,7 @@ const AuthenticatedSiteAdminArea: React.FunctionComponent<React.PropsWithChildre
144144
telemetryService: props.telemetryService,
145145
telemetryRecorder: props.telemetryRecorder,
146146
codeInsightsEnabled: props.codeInsightsEnabled,
147-
applianceManaged: props.applianceManaged,
147+
applianceUpdateTarget: props.applianceUpdateTarget,
148148
endUserOnboardingEnabled,
149149
}
150150

@@ -164,7 +164,7 @@ const AuthenticatedSiteAdminArea: React.FunctionComponent<React.PropsWithChildre
164164
batchChangesExecutionEnabled={props.batchChangesExecutionEnabled}
165165
batchChangesWebhookLogsEnabled={props.batchChangesWebhookLogsEnabled}
166166
codeInsightsEnabled={props.codeInsightsEnabled}
167-
applianceManaged={props.applianceManaged}
167+
applianceUpdateTarget={props.applianceUpdateTarget}
168168
endUserOnboardingEnabled={endUserOnboardingEnabled}
169169
/>
170170
<div className="flex-bounded">

client/web/src/site-admin/SiteAdminSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface SiteAdminSideBarGroupContext extends BatchChangesProps {
1515
isSourcegraphDotCom: boolean
1616
codeInsightsEnabled: boolean
1717
endUserOnboardingEnabled: boolean
18-
applianceManaged: boolean
18+
applianceUpdateTarget: string
1919
}
2020

2121
export interface SiteAdminSideBarGroup extends NavGroupDescriptor<SiteAdminSideBarGroupContext> {}

client/web/src/site-admin/sidebaritems.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ const maintenanceGroup: SiteAdminSideBarGroup = {
135135
{
136136
label: maintenanceGroupUpdatesItemLabel,
137137
to: '/site-admin/updates',
138-
condition: ({ applianceManaged }) => !applianceManaged,
138+
condition: ({ applianceUpdateTarget }) => applianceUpdateTarget === '',
139139
},
140140
{
141141
label: maintenanceGroupUpdatesItemLabel,
142-
to: '/appliance/updates',
143-
condition: ({ applianceManaged }) => applianceManaged,
142+
to: window.context.applianceUpdateTarget,
143+
condition: ({ applianceUpdateTarget }) => applianceUpdateTarget !== '',
144144
},
145145
{
146146
label: 'Documentation',

cmd/frontend/internal/app/jscontext/jscontext.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,15 +232,16 @@ type JSContext struct {
232232
CodeIntelAutoIndexingAllowGlobalPolicies bool `json:"codeIntelAutoIndexingAllowGlobalPolicies"`
233233
CodeIntelRankingDocumentReferenceCountsEnabled bool `json:"codeIntelRankingDocumentReferenceCountsEnabled"`
234234

235-
CodeInsightsEnabled bool `json:"codeInsightsEnabled"`
236-
ApplianceManaged bool `json:"applianceManaged"`
237-
CodeIntelligenceEnabled bool `json:"codeIntelligenceEnabled"`
238-
SearchContextsEnabled bool `json:"searchContextsEnabled"`
239-
NotebooksEnabled bool `json:"notebooksEnabled"`
240-
CodeMonitoringEnabled bool `json:"codeMonitoringEnabled"`
241-
SearchAggregationEnabled bool `json:"searchAggregationEnabled"`
242-
OwnEnabled bool `json:"ownEnabled"`
243-
SearchJobsEnabled bool `json:"searchJobsEnabled"`
235+
CodeInsightsEnabled bool `json:"codeInsightsEnabled"`
236+
ApplianceUpdateTarget string `json:"applianceUpdateTarget"`
237+
ApplianceMenuTarget string `json:"applianceMenuTarget"`
238+
CodeIntelligenceEnabled bool `json:"codeIntelligenceEnabled"`
239+
SearchContextsEnabled bool `json:"searchContextsEnabled"`
240+
NotebooksEnabled bool `json:"notebooksEnabled"`
241+
CodeMonitoringEnabled bool `json:"codeMonitoringEnabled"`
242+
SearchAggregationEnabled bool `json:"searchAggregationEnabled"`
243+
OwnEnabled bool `json:"ownEnabled"`
244+
SearchJobsEnabled bool `json:"searchJobsEnabled"`
244245

245246
RedirectUnsupportedBrowser bool `json:"RedirectUnsupportedBrowser"`
246247

@@ -437,7 +438,8 @@ func NewJSContextFromRequest(req *http.Request, db database.DB) JSContext {
437438
CodyRequiresVerifiedEmail: siteResolver.RequiresVerifiedEmailForCody(ctx),
438439

439440
CodeSearchEnabledOnInstance: codeSearchLicensed,
440-
ApplianceManaged: conf.IsApplianceManaged(),
441+
ApplianceUpdateTarget: conf.ApplianceUpdateTarget(),
442+
ApplianceMenuTarget: conf.ApplianceMenuTarget(),
441443

442444
ExecutorsEnabled: conf.ExecutorsEnabled(),
443445
CodeIntelAutoIndexingEnabled: conf.CodeIntelAutoIndexingEnabled(),

internal/conf/computed.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/url"
77
"os"
88
"slices"
9-
"strconv"
109
"strings"
1110
"time"
1211

@@ -535,11 +534,12 @@ func AuthPrimaryLoginProvidersCount() int {
535534
return c
536535
}
537536

538-
func IsApplianceManaged() bool {
539-
if v, _ := strconv.ParseBool(os.Getenv("APPLIANCE_MANAGED")); v {
540-
return v
541-
}
542-
return false
537+
func ApplianceUpdateTarget() string {
538+
return os.Getenv("APPLIANCE_UPDATE_TARGET")
539+
}
540+
541+
func ApplianceMenuTarget() string {
542+
return os.Getenv("APPLIANCE_MENU_TARGET")
543543
}
544544

545545
// SearchSymbolsParallelism returns 20, or the site config

0 commit comments

Comments
 (0)