Skip to content

Commit a3ad549

Browse files
heiskrvanessayuenn
andauthored
Block a few more things in AIRGAP (github#17657)
* Block a few more things in AIRGAP * Update middleware/context.js Co-authored-by: Vanessa Yuen <6842965+vanessayuenn@users.noreply.github.com> * Update product-landing.html Co-authored-by: Vanessa Yuen <6842965+vanessayuenn@users.noreply.github.com>
1 parent 4a23a3e commit a3ad549

11 files changed

Lines changed: 57 additions & 25 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ COPY --chown=node:node --from=install /usr/src/docs/dist /usr/src/docs/dist
4242
ENV NODE_ENV production
4343

4444
# Use Lunr instead of Algolia
45-
ENV USE_LUNR true
45+
ENV AIRGAP true
4646

4747
# Copy only what's needed to run the server
4848
COPY --chown=node:node assets ./assets

includes/explorer.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{% include breadcrumbs %}
22

33
<div class="graphql-container">
4-
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen>
5-
<p>You must have iframes enabled to use this feature.</p>
6-
</iframe>
4+
{% if process.env.AIRGAP %}
5+
<p>GraphQL explorer is not available on this environment.</p>
6+
{% else %}
7+
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen>
8+
<p>You must have iframes enabled to use this feature.</p>
9+
</iframe>
10+
{% endif %}
711
</div>

includes/scripts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
<script id="search-options" type="application/json">{{ searchOptions }}</script>
1+
<script id="expose" type="application/json">{{ expose }}</script>
22
<script src="{{ builtAssets.main.js }}"></script>

javascripts/airgap-links.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function airgapLinks () {
2+
// When in an airgapped environment,
3+
// show a tooltip on external links
4+
const { airgap } = JSON.parse(document.getElementById('expose').text)
5+
if (!airgap) return
6+
7+
const externaLinks = Array.from(
8+
document.querySelectorAll('a[href^="http"], a[href^="//"]')
9+
)
10+
externaLinks.forEach(link => {
11+
link.classList.add('tooltipped')
12+
link.setAttribute('aria-label', 'This link may not work in this environment.')
13+
})
14+
}

javascripts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import allArticles from './all-articles'
1818
import devToc from './dev-toc'
1919
import releaseNotes from './release-notes'
2020
import showMore from './show-more'
21+
import airgapLinks from './airgap-links'
2122

2223
document.addEventListener('DOMContentLoaded', async () => {
2324
displayPlatformSpecificContent()
@@ -34,6 +35,7 @@ document.addEventListener('DOMContentLoaded', async () => {
3435
allArticles()
3536
devToc()
3637
showMore()
38+
airgapLinks()
3739
releaseNotes()
3840
initializeEvents()
3941
experiment()

javascripts/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function search () {
2626
languages,
2727
versions,
2828
nonEnterpriseDefaultVersion
29-
} = JSON.parse(document.getElementById('search-options').text)
29+
} = JSON.parse(document.getElementById('expose').text).searchOptions
3030
version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion)
3131
language = deriveLanguageCodeFromPath(languages)
3232

layouts/graphql-explorer.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ <h1 class="border-bottom-0">{{ page.title }}</h1>
2020

2121
<div class="mt-2">
2222
<div>
23-
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}">
24-
<p>You must have iframes enabled to use this feature.</p>
25-
</iframe>
23+
{% if process.env.AIRGAP %}
24+
<p>GraphQL explorer is not available on this environment.</p>
25+
{% else %}
26+
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}">
27+
<p>You must have iframes enabled to use this feature.</p>
28+
</iframe>
29+
{% endif %}
2630
</div>
2731
</div>
2832
</article>

layouts/product-landing.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ <h1 class="mb-3 font-mktg">
4141
{% if page.product_video %}
4242
<div class="col-12 col-lg-6">
4343
<div class="position-relative" style="padding-bottom:56.25%;">
44-
<iframe
45-
title="{{ page.shortTitle }} Video"
46-
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
47-
src="{{ page.product_video }}"
48-
frameborder="0"
49-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
50-
></iframe>
44+
{% unless process.env.AIRGAP %}
45+
<iframe
46+
title="{{ page.shortTitle }} Video"
47+
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
48+
src="{{ page.product_video }}"
49+
frameborder="0"
50+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
51+
></iframe>
52+
{% endunless %}
5153
</div>
5254
</div>
5355
{% endif %}

lib/search/sync.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
7171

7272
// The page version will be the new version, e.g., free-pro-team@latest, enterprise-server@2.22
7373
const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode)
74-
const index = process.env.USE_LUNR
74+
const index = process.env.AIRGAP
7575
? new LunrIndex(indexName, records)
7676
: new AlgoliaIndex(indexName, records)
7777

@@ -80,7 +80,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
8080
fs.writeFileSync(cacheFile, JSON.stringify(index, null, 2))
8181
console.log('wrote dry-run index to disk: ', cacheFile)
8282
} else {
83-
if (process.env.USE_LUNR) {
83+
if (process.env.AIRGAP) {
8484
await index.write()
8585
console.log('wrote index to file: ', indexName)
8686
} else {
@@ -93,7 +93,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
9393

9494
// Fetch a list of index names and cache it for tests
9595
// to ensure that an index exists for every language and GHE version
96-
const remoteIndexNames = process.env.USE_LUNR
96+
const remoteIndexNames = process.env.AIRGAP
9797
? await getLunrIndexNames()
9898
: await getRemoteIndexNames()
9999
const cachedIndexNamesFile = path.join(__dirname, './cached-index-names.json')

middleware/context.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = async function contextualize (req, res, next) {
2424
featureFlags.forEach(featureFlagName => {
2525
req.context.process.env[featureFlagName] = process.env[featureFlagName]
2626
})
27+
if (process.env.AIRGAP) req.context.process.env.AIRGAP = true
2728

2829
// define each context property explicitly for code-search friendliness
2930
// e.g. searches for "req.context.page" will include results from this file
@@ -48,11 +49,16 @@ module.exports = async function contextualize (req, res, next) {
4849
// JS + CSS asset paths
4950
req.context.builtAssets = builtAssets
5051

51-
// Languages and versions for search
52-
req.context.searchOptions = JSON.stringify({
53-
languages: Object.keys(languages),
54-
versions: searchVersions,
55-
nonEnterpriseDefaultVersion
52+
// Object exposing selected variables to client
53+
req.context.expose = JSON.stringify({
54+
// Languages and versions for search
55+
searchOptions: {
56+
languages: Object.keys(languages),
57+
versions: searchVersions,
58+
nonEnterpriseDefaultVersion
59+
},
60+
// `|| undefined` won't show at all for production
61+
airgap: Boolean(process.env.AIRGAP) || undefined
5662
})
5763

5864
return next()

0 commit comments

Comments
 (0)