Skip to content

Commit ed55bdb

Browse files
committed
[core] Expose deployment constants (including consul_endpoint) to env
1 parent 38e2e5c commit ed55bdb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

core/confsys/service.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"encoding/json"
2929
"errors"
3030
"io/ioutil"
31+
"net/url"
3132
"os"
3233
"path/filepath"
3334
"strconv"
@@ -220,7 +221,23 @@ func (s *Service) GetROSource() configuration.ROSource {
220221
// response: but not all of them! some vars will likely only get parsed at deployment time i.e. right
221222
// before pushing TaskInfos
222223
func (s *Service) GetDefaults() map[string]string {
223-
return s.getStringMap(filepath.Join(s.GetConsulPath(),"defaults"))
224+
smap := s.getStringMap(filepath.Join(s.GetConsulPath(),"defaults"))
225+
226+
// Fill in some global constants we want to make available everywhere
227+
globalConfigurationUri := viper.GetString("globalConfigurationUri")
228+
smap["consul_base_uri"] = globalConfigurationUri
229+
consulUrl, err := url.ParseRequestURI(globalConfigurationUri)
230+
if err == nil {
231+
smap["consul_hostname"] = consulUrl.Hostname()
232+
smap["consul_port"] = consulUrl.Port()
233+
smap["consul_endpoint"] = consulUrl.Host
234+
} else {
235+
log.WithField("globalConfigurationUri", globalConfigurationUri).
236+
Warn("cannot parse global configuration endpoint")
237+
}
238+
smap["framework_id"], _ = s.GetMesosFID()
239+
smap["core_hostname"], _ = os.Hostname()
240+
return smap
224241
}
225242

226243
func (s *Service) GetVars() map[string]string {

0 commit comments

Comments
 (0)