Skip to content

Commit

Permalink
fix: update sample & default BROKER_CLIENT_HOST
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Aug 26, 2016
1 parent 35d7219 commit df0c869
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 16 deletions.
15 changes: 12 additions & 3 deletions client-templates/snyk/.env.sample
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
# your unique broker identifier
BROKER_ID=

# the host where your github enterprise is running, i.e. api.github.com
HOST=

# your personal access token to your github enterprise account
TOKEN=

# the host where your github enterprise is running, i.e. api.github.com, note
# that this doesn't include the API URL, as that's set in $GITHUB_API
GITHUB=

GITHUB_API=$GITHUB/api/v3

# optionally the client host (including port) - otherwise this defaults to localhost:$PORT
# BROKER_CLIENT_HOST=

# snyk specific configuration
BROKER_URL=https://broker.snyk.io

# the fine detail accept rules that allow snyk to make API requests to your
# github enterprise instance
ACCEPT=accept.json
71 changes: 59 additions & 12 deletions client-templates/snyk/accept.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
{
"//": "used for pushing up webhooks from github",
"method": "POST",
"path": "/",
"path": "/webhook/github",
"valid": [
{
"//": "accept all pull request state changes (these don't have files in them)",
"path": "pull_request.state",
"value": "open"
},
{
"path": "commits.*.added.*",
"value": "package.json"
Expand All @@ -27,72 +32,114 @@
],
"private":
[
{
"//": "list the user's repos",
"method": "GET",
"path": "/user/repos",
"origin": "https://${TOKEN}@${GITHUB_API}"
},

{
"//": "rate limit check",
"method": "GET",
"path": "/rate_limit",
"origin": "https://${TOKEN}@${GITHUB_API}"
},

{
"//": "allow meta lookup on the api version",
"method": "GET",
"path": "/",
"origin": "https://${TOKEN}@${GITHUB_API}"
},

{
"//": "allow webhooks to be added, to allow commits to be checked by Snyk. Rules for what is sent to Snyk are controlled in the `public` accept filters",
"method": "POST",
"path": "/repos/:user/:repo/hooks",
"origin": "https://${TOKEN}@${GITHUB_API}"
},

{
"//": "used to create commit status messages",
"method": "POST",
"path": "/repos/:user/:repo/statuses/:sha",
"origin": "https://${TOKEN}@${GITHUB_API}"
},

{
"//": "check if repo is public",
"method": "GET",
"path": "/:user/:repo",
"origin": "https://${TOKEN}@${GITHUB}"
},

{
"//": "used to determine the full dependency tree",
"method": "GET",
"path": "/:name/:repo/:branch/package.json",
"origin": "https://${TOKEN}@${HOST}/raw"
"origin": "https://${TOKEN}@${GITHUB}/raw"
},
{
"//": "used to check if there's any ignore rules or existing patches",
"method": "GET",
"path": "/:name/:repo/:branch/.snyk",
"origin": "https://${TOKEN}@${HOST}/raw"
"origin": "https://${TOKEN}@${GITHUB}/raw"
},

{
"//": "get details of the repo",
"method": "GET",
"path": "/repos/:name/:repo",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "get a list of all the refs to match find whether an existing PR is open",
"method": "GET",
"path": "/repos/:name/:repo/git/refs",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "get the details of an individual ref",
"method": "GET",
"path": "/repos/:name/:repo/git/refs/:ref",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "search for open snyk pull requests",
"method": "GET",
"path": "/repos/:name/:repo/pulls",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "add the individual commit for the pull requests",
"method": "POST",
"path": "/repos/:name/:repo/git/commits",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "add commit data for new PR",
"method": "POST",
"path": "/repos/:name/:repo/git/refs",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "create the ref to add the commits to",
"method": "POST",
"path": "/repos/:name/:repo/git/trees",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "create the pull request",
"method": "POST",
"path": "/repos/:name/:repo/pulls",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
},
{
"//": "update ref",
"method": "PATCH",
"path": "/repos/:name/:repo/git/refs/:sha",
"origin": "https://${TOKEN}@${HOST}"
"origin": "https://${TOKEN}@${GITHUB_API}"
}
]
}
4 changes: 3 additions & 1 deletion lib/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ expand(dotenv.config({
path: process.cwd() + '/.env',
}));

module.exports = Object.assign({}, camelify(config), camelify(process.env));
const res = Object.assign({}, camelify(config), camelify(process.env));

module.exports = res;
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ function main({ port, client } = {}) {
client = !!config.brokerUrl;
}

if (!config.BROKER_CLIENT_HOST) {
const proto = !config.key && !config.cert ? 'http' : 'https';
config.BROKER_CLIENT_HOST = `${proto}://localhost:${port || config.port}`;
}

const method = client ? 'client' : 'server';
process.env.BROKER_TYPE = method;

Expand Down

0 comments on commit df0c869

Please sign in to comment.