-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send better user-agent values (and got config changes) (#7309)
* expose fetchLimitBytes/userAgent in got-config module * export a function not a factory * send better user-agent values - add userAgentBase setting - send short SHA in user agent on heroku - set a version (tag or short SHA) in Dockefile and use it to report server version in UA for docker users * add a comment explaining fileSize Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
95a439a
commit 99bffd3
Showing
22 changed files
with
113 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ jobs: | |
context: . | ||
push: false | ||
tags: shieldsio/shields:pr-validation | ||
build-args: | | ||
version=${GITHUB_SHA::7} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ jobs: | |
context: . | ||
push: true | ||
tags: shieldsio/shields:next | ||
build-args: | | ||
version=${GITHUB_SHA::7} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import bytes from 'bytes' | ||
import configModule from 'config' | ||
import Joi from 'joi' | ||
import { fileSize } from '../../services/validators.js' | ||
|
||
const schema = Joi.object({ | ||
fetchLimit: fileSize, | ||
userAgentBase: Joi.string().required(), | ||
}).required() | ||
const config = configModule.util.toObject() | ||
const publicConfig = Joi.attempt(config.public, schema, { allowUnknown: true }) | ||
|
||
const fetchLimitBytes = bytes(publicConfig.fetchLimit) | ||
|
||
function getUserAgent(userAgentBase = publicConfig.userAgentBase) { | ||
let version = 'dev' | ||
if (process.env.DOCKER_SHIELDS_VERSION) { | ||
version = process.env.DOCKER_SHIELDS_VERSION | ||
} | ||
if (process.env.HEROKU_SLUG_COMMIT) { | ||
version = process.env.HEROKU_SLUG_COMMIT.substring(0, 7) | ||
} | ||
return `${userAgentBase}/${version}` | ||
} | ||
|
||
export { fetchLimitBytes, getUserAgent } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { expect } from 'chai' | ||
import { getUserAgent } from './got-config.js' | ||
|
||
describe('getUserAgent function', function () { | ||
afterEach(function () { | ||
delete process.env.HEROKU_SLUG_COMMIT | ||
delete process.env.DOCKER_SHIELDS_VERSION | ||
}) | ||
|
||
it('uses the default userAgentBase', function () { | ||
expect(getUserAgent()).to.equal('shields (self-hosted)/dev') | ||
}) | ||
|
||
it('applies custom userAgentBase', function () { | ||
expect(getUserAgent('custom')).to.equal('custom/dev') | ||
}) | ||
|
||
it('uses short commit SHA from HEROKU_SLUG_COMMIT if available', function () { | ||
process.env.HEROKU_SLUG_COMMIT = '92090bd44742a5fac03bcb117002088fc7485834' | ||
expect(getUserAgent('custom')).to.equal('custom/92090bd') | ||
}) | ||
|
||
it('uses short commit SHA from DOCKER_SHIELDS_VERSION if available', function () { | ||
process.env.DOCKER_SHIELDS_VERSION = 'server-2021-11-22' | ||
expect(getUserAgent('custom')).to.equal('custom/server-2021-11-22') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.