Skip to content

Commit

Permalink
Block a few more things in AIRGAP (github#17657)
Browse files Browse the repository at this point in the history
* Block a few more things in AIRGAP

* Update middleware/context.js

Co-authored-by: Vanessa Yuen <[email protected]>

* Update product-landing.html

Co-authored-by: Vanessa Yuen <[email protected]>
  • Loading branch information
heiskr and vanessayuenn authored Feb 9, 2021
1 parent 4a23a3e commit a3ad549
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ COPY --chown=node:node --from=install /usr/src/docs/dist /usr/src/docs/dist
ENV NODE_ENV production

# Use Lunr instead of Algolia
ENV USE_LUNR true
ENV AIRGAP true

# Copy only what's needed to run the server
COPY --chown=node:node assets ./assets
Expand Down
10 changes: 7 additions & 3 deletions includes/explorer.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{% include breadcrumbs %}

<div class="graphql-container">
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen>
<p>You must have iframes enabled to use this feature.</p>
</iframe>
{% if process.env.AIRGAP %}
<p>GraphQL explorer is not available on this environment.</p>
{% else %}
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen>
<p>You must have iframes enabled to use this feature.</p>
</iframe>
{% endif %}
</div>
2 changes: 1 addition & 1 deletion includes/scripts.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<script id="search-options" type="application/json">{{ searchOptions }}</script>
<script id="expose" type="application/json">{{ expose }}</script>
<script src="{{ builtAssets.main.js }}"></script>
14 changes: 14 additions & 0 deletions javascripts/airgap-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function airgapLinks () {
// When in an airgapped environment,
// show a tooltip on external links
const { airgap } = JSON.parse(document.getElementById('expose').text)
if (!airgap) return

const externaLinks = Array.from(
document.querySelectorAll('a[href^="http"], a[href^="//"]')
)
externaLinks.forEach(link => {
link.classList.add('tooltipped')
link.setAttribute('aria-label', 'This link may not work in this environment.')
})
}
2 changes: 2 additions & 0 deletions javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import allArticles from './all-articles'
import devToc from './dev-toc'
import releaseNotes from './release-notes'
import showMore from './show-more'
import airgapLinks from './airgap-links'

document.addEventListener('DOMContentLoaded', async () => {
displayPlatformSpecificContent()
Expand All @@ -34,6 +35,7 @@ document.addEventListener('DOMContentLoaded', async () => {
allArticles()
devToc()
showMore()
airgapLinks()
releaseNotes()
initializeEvents()
experiment()
Expand Down
2 changes: 1 addition & 1 deletion javascripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function search () {
languages,
versions,
nonEnterpriseDefaultVersion
} = JSON.parse(document.getElementById('search-options').text)
} = JSON.parse(document.getElementById('expose').text).searchOptions
version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion)
language = deriveLanguageCodeFromPath(languages)

Expand Down
10 changes: 7 additions & 3 deletions layouts/graphql-explorer.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ <h1 class="border-bottom-0">{{ page.title }}</h1>

<div class="mt-2">
<div>
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}">
<p>You must have iframes enabled to use this feature.</p>
</iframe>
{% if process.env.AIRGAP %}
<p>GraphQL explorer is not available on this environment.</p>
{% else %}
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}">
<p>You must have iframes enabled to use this feature.</p>
</iframe>
{% endif %}
</div>
</div>
</article>
Expand Down
16 changes: 9 additions & 7 deletions layouts/product-landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ <h1 class="mb-3 font-mktg">
{% if page.product_video %}
<div class="col-12 col-lg-6">
<div class="position-relative" style="padding-bottom:56.25%;">
<iframe
title="{{ page.shortTitle }} Video"
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
src="{{ page.product_video }}"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
></iframe>
{% unless process.env.AIRGAP %}
<iframe
title="{{ page.shortTitle }} Video"
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
src="{{ page.product_video }}"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
></iframe>
{% endunless %}
</div>
</div>
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions lib/search/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {

// The page version will be the new version, e.g., free-pro-team@latest, [email protected]
const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode)
const index = process.env.USE_LUNR
const index = process.env.AIRGAP
? new LunrIndex(indexName, records)
: new AlgoliaIndex(indexName, records)

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

// Fetch a list of index names and cache it for tests
// to ensure that an index exists for every language and GHE version
const remoteIndexNames = process.env.USE_LUNR
const remoteIndexNames = process.env.AIRGAP
? await getLunrIndexNames()
: await getRemoteIndexNames()
const cachedIndexNamesFile = path.join(__dirname, './cached-index-names.json')
Expand Down
16 changes: 11 additions & 5 deletions middleware/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = async function contextualize (req, res, next) {
featureFlags.forEach(featureFlagName => {
req.context.process.env[featureFlagName] = process.env[featureFlagName]
})
if (process.env.AIRGAP) req.context.process.env.AIRGAP = true

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

// Languages and versions for search
req.context.searchOptions = JSON.stringify({
languages: Object.keys(languages),
versions: searchVersions,
nonEnterpriseDefaultVersion
// Object exposing selected variables to client
req.context.expose = JSON.stringify({
// Languages and versions for search
searchOptions: {
languages: Object.keys(languages),
versions: searchVersions,
nonEnterpriseDefaultVersion
},
// `|| undefined` won't show at all for production
airgap: Boolean(process.env.AIRGAP) || undefined
})

return next()
Expand Down
2 changes: 1 addition & 1 deletion middleware/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ router.get('/', async (req, res) => {
}

try {
const results = process.env.USE_LUNR
const results = process.env.AIRGAP
? await loadLunrResults({ version, language, query, limit })
: await loadAlgoliaResults({ version, language, query, limit })
return res.status(200).json(results)
Expand Down

0 comments on commit a3ad549

Please sign in to comment.