1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Block a few more things in AIRGAP (#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>
This commit is contained in:
Kevin Heis
2021-02-09 15:07:23 -08:00
committed by GitHub
parent 4a23a3e675
commit a3ad549e39
11 changed files with 57 additions and 25 deletions

View File

@@ -42,7 +42,7 @@ COPY --chown=node:node --from=install /usr/src/docs/dist /usr/src/docs/dist
ENV NODE_ENV production ENV NODE_ENV production
# Use Lunr instead of Algolia # Use Lunr instead of Algolia
ENV USE_LUNR true ENV AIRGAP true
# Copy only what's needed to run the server # Copy only what's needed to run the server
COPY --chown=node:node assets ./assets COPY --chown=node:node assets ./assets

View File

@@ -1,7 +1,11 @@
{% include breadcrumbs %} {% include breadcrumbs %}
<div class="graphql-container"> <div class="graphql-container">
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}" allowfullscreen> {% if process.env.AIRGAP %}
<p>You must have iframes enabled to use this feature.</p> <p>GraphQL explorer is not available on this environment.</p>
</iframe> {% 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> </div>

View File

@@ -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> <script src="{{ builtAssets.main.js }}"></script>

View File

@@ -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.')
})
}

View File

@@ -18,6 +18,7 @@ import allArticles from './all-articles'
import devToc from './dev-toc' import devToc from './dev-toc'
import releaseNotes from './release-notes' import releaseNotes from './release-notes'
import showMore from './show-more' import showMore from './show-more'
import airgapLinks from './airgap-links'
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
displayPlatformSpecificContent() displayPlatformSpecificContent()
@@ -34,6 +35,7 @@ document.addEventListener('DOMContentLoaded', async () => {
allArticles() allArticles()
devToc() devToc()
showMore() showMore()
airgapLinks()
releaseNotes() releaseNotes()
initializeEvents() initializeEvents()
experiment() experiment()

View File

@@ -26,7 +26,7 @@ export default function search () {
languages, languages,
versions, versions,
nonEnterpriseDefaultVersion nonEnterpriseDefaultVersion
} = JSON.parse(document.getElementById('search-options').text) } = JSON.parse(document.getElementById('expose').text).searchOptions
version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion) version = deriveVersionFromPath(versions, nonEnterpriseDefaultVersion)
language = deriveLanguageCodeFromPath(languages) language = deriveLanguageCodeFromPath(languages)

View File

@@ -20,9 +20,13 @@
<div class="mt-2"> <div class="mt-2">
<div> <div>
<iframe id="graphiql" class="graphql-explorer" scrolling="no" src="{{ graphql.explorerUrl }}"> {% if process.env.AIRGAP %}
<p>You must have iframes enabled to use this feature.</p> <p>GraphQL explorer is not available on this environment.</p>
</iframe> {% 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>
</div> </div>
</article> </article>

View File

@@ -41,13 +41,15 @@
{% if page.product_video %} {% if page.product_video %}
<div class="col-12 col-lg-6"> <div class="col-12 col-lg-6">
<div class="position-relative" style="padding-bottom:56.25%;"> <div class="position-relative" style="padding-bottom:56.25%;">
<iframe {% unless process.env.AIRGAP %}
title="{{ page.shortTitle }} Video" <iframe
class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full" title="{{ page.shortTitle }} Video"
src="{{ page.product_video }}" class="top-0 left-0 position-absolute box-shadow-large rounded-1 width-full height-full"
frameborder="0" src="{{ page.product_video }}"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen frameborder="0"
></iframe> allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen
></iframe>
{% endunless %}
</div> </div>
</div> </div>
{% endif %} {% endif %}

View File

@@ -71,7 +71,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
// The page version will be the new version, e.g., free-pro-team@latest, enterprise-server@2.22 // The page version will be the new version, e.g., free-pro-team@latest, enterprise-server@2.22
const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode) const records = await buildRecords(indexName, indexablePages, pageVersion, languageCode)
const index = process.env.USE_LUNR const index = process.env.AIRGAP
? new LunrIndex(indexName, records) ? new LunrIndex(indexName, records)
: new AlgoliaIndex(indexName, records) : new AlgoliaIndex(indexName, records)
@@ -80,7 +80,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
fs.writeFileSync(cacheFile, JSON.stringify(index, null, 2)) fs.writeFileSync(cacheFile, JSON.stringify(index, null, 2))
console.log('wrote dry-run index to disk: ', cacheFile) console.log('wrote dry-run index to disk: ', cacheFile)
} else { } else {
if (process.env.USE_LUNR) { if (process.env.AIRGAP) {
await index.write() await index.write()
console.log('wrote index to file: ', indexName) console.log('wrote index to file: ', indexName)
} else { } else {
@@ -93,7 +93,7 @@ module.exports = async function syncSearchIndexes (opts = {}) {
// Fetch a list of index names and cache it for tests // Fetch a list of index names and cache it for tests
// to ensure that an index exists for every language and GHE version // 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 getLunrIndexNames()
: await getRemoteIndexNames() : await getRemoteIndexNames()
const cachedIndexNamesFile = path.join(__dirname, './cached-index-names.json') const cachedIndexNamesFile = path.join(__dirname, './cached-index-names.json')

View File

@@ -24,6 +24,7 @@ module.exports = async function contextualize (req, res, next) {
featureFlags.forEach(featureFlagName => { featureFlags.forEach(featureFlagName => {
req.context.process.env[featureFlagName] = process.env[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 // define each context property explicitly for code-search friendliness
// e.g. searches for "req.context.page" will include results from this file // 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) {
// JS + CSS asset paths // JS + CSS asset paths
req.context.builtAssets = builtAssets req.context.builtAssets = builtAssets
// Languages and versions for search // Object exposing selected variables to client
req.context.searchOptions = JSON.stringify({ req.context.expose = JSON.stringify({
languages: Object.keys(languages), // Languages and versions for search
versions: searchVersions, searchOptions: {
nonEnterpriseDefaultVersion languages: Object.keys(languages),
versions: searchVersions,
nonEnterpriseDefaultVersion
},
// `|| undefined` won't show at all for production
airgap: Boolean(process.env.AIRGAP) || undefined
}) })
return next() return next()

View File

@@ -22,7 +22,7 @@ router.get('/', async (req, res) => {
} }
try { try {
const results = process.env.USE_LUNR const results = process.env.AIRGAP
? await loadLunrResults({ version, language, query, limit }) ? await loadLunrResults({ version, language, query, limit })
: await loadAlgoliaResults({ version, language, query, limit }) : await loadAlgoliaResults({ version, language, query, limit })
return res.status(200).json(results) return res.status(200).json(results)