Skip to content

Commit

Permalink
Add versions call to status (looker-open-source#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryans99 authored Oct 15, 2020
1 parent 0dc061d commit 427242c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/access-token-server/src/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import { readFileSync } from 'fs'
import { cwd } from 'process'
import { Router } from 'express'
import { verifyLookerServer } from '../services/looker_auth'

const router = Router()

Expand All @@ -47,6 +48,8 @@ router.get('/status', async (req, res) => {
statusCode = 542
status.errors.push('failed to read or parse status.json file')
}
const serverStatus = await verifyLookerServer()
status = { ...status, ...serverStatus }
res.setHeader('Content-Type', 'application/json')
res.status(statusCode).send(JSON.stringify(status))
})
Expand Down
20 changes: 20 additions & 0 deletions examples/access-token-server/src/services/looker_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,23 @@ export const validateLookerCredentials = async (
return false
}
}

export const verifyLookerServer = async () => {
const lookerSettings = DefaultSettings()
const settings = getSettings()
lookerSettings.base_url = settings.lookerServerUrl
lookerSettings.verify_ssl = settings.lookerServerVerifySsl
const session = new NodeSession(lookerSettings)
try {
const result = await session.transport.rawRequest('GET', '/versions')
return {
looker_server_url: settings.lookerServerUrl,
looker_server_reachable: true,
}
} catch (error) {
return {
looker_server_url: settings.lookerServerUrl,
looker_server_reachable: false,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ describe('access_token_server', () => {
expect(json.build_date).toBeDefined()
expect(json.git_commit).toBeDefined()
expect(json.access_token_server_provider_label).toBeDefined()
expect(json.looker_server_url).toBeDefined()
expect(json.looker_server_reachable).toBeTruthy()
})

test.each([
Expand Down

0 comments on commit 427242c

Please sign in to comment.