Skip to content

Commit

Permalink
feat: add status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kopp committed Nov 10, 2022
1 parent 7623239 commit a0a1cd7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/plugins/remote-cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FastifyInstance } from 'fastify'
import { badRequest, unauthorized } from '@hapi/boom'
import { getArtifact, putArtifact, artifactsEvents, headArtifact } from './routes'
import { getArtifact, putArtifact, artifactsEvents, headArtifact, getStatus } from './routes'
import { createLocation } from './storage'
import { STORAGE_PROVIDERS } from '../../env'

Expand Down Expand Up @@ -63,6 +63,7 @@ async function turboRemoteCache(
i.route(headArtifact)
i.route(putArtifact)
i.route(artifactsEvents)
i.route(getStatus)
},
{ prefix: `/${apiVersion}` },
)
Expand Down
21 changes: 21 additions & 0 deletions src/plugins/remote-cache/routes/get-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Server } from 'http'
import type { RawReplyDefaultExpression, RawRequestDefaultExpression, RouteOptions } from 'fastify'
import { type Params, type Querystring } from './schema'
import { statusRouteSchema } from './status-schema'

export const getStatus: RouteOptions<
Server,
RawRequestDefaultExpression,
RawReplyDefaultExpression,
{
Querystring: Querystring
Params: Params
}
> = {
method: 'GET',
url: '/artifacts/status',
schema: statusRouteSchema,
async handler(req, reply) {
reply.send({ status: 'enabled' })
},
}
1 change: 1 addition & 0 deletions src/plugins/remote-cache/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { getArtifact } from './get-artifact'
export { headArtifact } from './head-artifact'
export { putArtifact } from './put-artifact'
export { artifactsEvents } from './artifacts-events'
export { getStatus } from './get-status'
12 changes: 12 additions & 0 deletions src/plugins/remote-cache/routes/status-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Static, Type } from '@sinclair/typebox'

const querystring = Type.Object({}, { additionalParameters: false })
export type Querystring = Static<typeof querystring>

const params = Type.Object({}, { additionalParameters: false })
export type Params = Static<typeof params>

export const statusRouteSchema = {
querystring,
params,
}
12 changes: 12 additions & 0 deletions test/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,16 @@ test(`local'`, async t => {
t2.equal(response.statusCode, 200)
t2.same(response.json(), {})
})
t.test('should return 200 when GET artifacts/status is called', async t2 => {
t2.plan(2)
const response = await app.inject({
method: 'GET',
url: `/v8/artifacts/status`,
headers: {
authorization: 'Bearer changeme',
},
})
t2.equal(response.statusCode, 200)
t2.same(response.json(), { status: 'enabled' })
})
})

0 comments on commit a0a1cd7

Please sign in to comment.