Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: added more headers to checkForUpdates #1170

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions garden-service/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import axios from "axios"
import chalk from "chalk"
import ci = require("ci-info")
import { pathExists } from "fs-extra"
import { difference, flatten, range, reduce } from "lodash"
import moment = require("moment")
import { platform, release } from "os"
import qs = require("qs")

import {
ChoicesParameter,
ParameterValues,
Expand All @@ -18,15 +25,10 @@ import {
} from "../exceptions"
import { LogLevel } from "../logger/log-node"
import { getEnumKeys, getPackageVersion } from "../util/util"
import axios from "axios"
import qs = require("qs")
import { platform, release } from "os"
import { LogEntry } from "../logger/log-entry"
import { STATIC_DIR, VERSION_CHECK_URL } from "../constants"
import { printWarningMessage } from "../logger/util"
import { GlobalConfigStore, globalConfigKeys } from "../config-store"
import moment = require("moment")
import { pathExists } from "fs-extra"

// Parameter types T which map between the Parameter<T> class and the Sywac cli library.
// In case we add types that aren't supported natively by Sywac, see: http://sywac.io/docs/sync-config.html#custom
Expand Down Expand Up @@ -239,7 +241,15 @@ export async function checkForUpdates(config: GlobalConfigStore, logger: LogEntr
platformVersion: release(),
}
try {
const res = await axios.get(`${VERSION_CHECK_URL}?${qs.stringify(query)}`)
const globalConfig = await config.get()
const headers = {}
headers["X-user-id"] = globalConfig.analytics ? globalConfig.analytics.userId : "unknown"
headers["X-ci-check"] = ci.isCI
if (ci.isCI) {
headers["X-ci-name"] = ci.name
}

const res = await axios.get(`${VERSION_CHECK_URL}?${qs.stringify(query)}`, { headers })
const configObj = await config.get()
const showMessage = (configObj.lastVersionCheck
&& moment().subtract(1, "days").isAfter(moment(configObj.lastVersionCheck.lastRun)))
Expand Down