use Cloudflare env variables or file

This commit is contained in:
Gleb Bahmutov
2017-09-15 15:54:40 -04:00
parent bf9de40945
commit fef9c24c1b
+22 -2
View File
@@ -58,6 +58,26 @@ module.exports = {
console.log("target directory %s", dirName)
dirName
hasCloudflareEnvironmentVars: () ->
check.unemptyString(process.env.CF_TOKEN) &&
check.unemptyString(process.env.CF_EMAIL) &&
check.unemptyString(process.env.CF_DOMAIN)
# depends on the credentials file or environment variables
makeCloudflarePurgeCommand: (url) ->
configFile = path.resolve(__dirname, "support", ".cfcli.yml")
if fs.existsSync(configFile)
console.log("using CF credentials file")
return "cfcli purgefile -c #{configFile} #{url}"
else if @hasCloudflareEnvironmentVars()
console.log("using CF environment variables")
token = process.env.CF_TOKEN
email = process.env.CF_EMAIL
domain = process.env.CF_DOMAIN
return "cfcli purgefile -e #{email} -k #{token} -d #{domain} #{url}"
else
throw new Error("Cannot form Cloudflare purge command without credentials")
purgeCache: ({version, platform}) ->
la(check.unemptyString(platform), "missing platform", platform)
la(check.unemptyString(zipName), "missing zip filename")
@@ -69,8 +89,8 @@ module.exports = {
url = [konfig("cdn_url"), "desktop", version, osName, zipName].join("/")
console.log("purging url", url)
configFile = path.resolve(__dirname, "support", ".cfcli.yml")
cp.exec "cfcli purgefile -c #{configFile} #{url}", (err, stdout, stderr) ->
purgeCommand = @makeCloudflarePurgeCommand(url)
cp.exec purgeCommand, (err, stdout, stderr) ->
if err
console.error("Could not purge #{url}")
console.error(err.message)