Skip to content

Commit

Permalink
Merge pull request #1 from omadawn/srvVarsFromEnv
Browse files Browse the repository at this point in the history
Use server settings from environment
  • Loading branch information
grafov authored Nov 22, 2017
2 parents 89192f7 + 8bff2b4 commit fe93556
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
143 changes: 143 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,146 @@ _testmain.go
*.prof
*.json
/cmd/grafana-backup/grafana-backup


# Ignored the compiled binary
grafana-backup

# Created by https://www.gitignore.io/api/go,eclipse,intellij+all

### Eclipse ###

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

### Eclipse Patch ###
# Eclipse Core
.project

# JDT-specific (Eclipse Java Development Tools)
.classpath

### Go ###
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Ruby plugin and RubyMine
/.rakeTasks

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Intellij+all Patch ###
# Ignores the whole idea folder
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# End of https://www.gitignore.io/api/go,eclipse,intellij+all
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var (
// The args after flags.
argCommand string
argPath = "*"

// Environment variables to read from
tokenKey = "GRAFANA_TOKEN" // Becomes flagServerKey
urlKey = "GRAFANA_URL" // Becomes flagServerURL
)

var cancel = make(chan os.Signal, 1)
Expand All @@ -62,10 +66,24 @@ func main() {
// TODO parse config here

flag.Parse()
// We need at minimum a command to execute so throw the printUsage if we don't have > 0 args
if flag.NArg() == 0 {
printUsage()
os.Exit(2)
}

// Set Token and URL from environment variables if they are present.
varToken := os.Getenv(tokenKey)
varURL := os.Getenv(urlKey)

if varToken != "" {
*flagServerKey = varToken
}

if varURL != "" {
*flagServerURL = varURL
}

var args = flag.Args()
// First mandatory argument is command.
argCommand = args[0]
Expand Down

0 comments on commit fe93556

Please sign in to comment.