Merge pull request #84 from influxdata/js-transpiler-fix-org-parameter

fix(cmd/transpilerd): fix transpilerd to use only --org-id
pull/10616/head
Jonathan A. Sternberg 2018-05-30 16:54:56 -05:00 committed by GitHub
commit e18ca56fb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 17 deletions

View File

@ -49,11 +49,8 @@ func init() {
viper.BindEnv("IFQLD_HOSTS")
viper.BindPFlag("IFQLD_HOSTS", transpileCmd.PersistentFlags().Lookup("ifqld-hosts"))
transpileCmd.PersistentFlags().StringP("org", "o", "", "name of the organization that owns the bucket")
viper.BindEnv("ORG")
viper.BindPFlag("ORG", transpileCmd.PersistentFlags().Lookup("org"))
transpileCmd.PersistentFlags().StringP("org-id", "", "", "id of the organization that owns the bucket")
// TODO(jsternberg): Determine how we are going to identify the organization id in open source.
transpileCmd.PersistentFlags().StringP("org-id", "", "0000000000000000", "id of the organization that owns the bucket")
viper.BindEnv("ORG_ID")
viper.BindPFlag("ORG_ID", transpileCmd.PersistentFlags().Lookup("org-id"))
}
@ -67,14 +64,14 @@ func transpileF(cmd *cobra.Command, logger *zap.Logger, args []string) error {
}
// Retrieve the organization that we are using.
id, err := getOrganization(cmd)
id, err := getOrganization()
if err != nil {
return err
}
// TODO(nathanielc): Allow QueryService to use multiple hosts.
logger.Info("Using ifqld service", zap.Strings("hosts", hosts))
logger.Info("Using ifqld service", zap.Strings("hosts", hosts), zap.Stringer("org-id", id))
transpileHandler := http.NewTranspilerQueryHandler(id)
transpileHandler.QueryService = &http.QueryService{
Addr: hosts[0],
@ -106,21 +103,18 @@ func getStrList(key string) ([]string, error) {
return strings.Split(valStr, ","), nil
}
func getOrganization(cmd *cobra.Command) (platform.ID, error) {
func getOrganization() (platform.ID, error) {
v := viper.GetViper()
orgName := v.GetString("ORG")
orgID := v.GetString("ORG_ID")
if (orgName != "" && orgID != "") || (orgName == "" && orgID == "") {
return nil, errors.New("must specify exactly one of org or org-id")
if orgID == "" {
return nil, errors.New("must specify org-id")
}
if orgID != "" {
var id platform.ID
if err := id.DecodeFromString(orgID); err != nil {
return nil, fmt.Errorf("unable to decode organization id: %s", err)
}
var id platform.ID
if err := id.DecodeFromString(orgID); err != nil {
return nil, fmt.Errorf("unable to decode organization id: %s", err)
}
return platform.ID(orgName), nil
return id, nil
}
func discoverHosts() ([]string, error) {