# Make variable configurable for plugin and reference in code

**URL:** <https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414>\
**Category:** Kibana\
**Created:** [July 10, 2018, 6:13pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414 "2018-07-10T18:13:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakey](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@rakey](https://discuss.elastic.co/u/rakey)\
**Post date:** [July 10, 2018, 6:13pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/1 "2018-07-10T18:13:22Z")

</div>

using kibana 5.5.1. The aim is to make a variable through kibana.yml whose edits can be implemented without deleting and re-compiling the optimization folder. Below is the index.js

export default function (kibana) {  
return new kibana.Plugin({  
id:'my\_team\_plugin',  
uiExports: {  
docViews: ['plugins/my\_team\_plugin/team\_plugin']

```
	},
	config: function (Joi) {
		return Joi.object({
			enabled: Joi.boolean().default(true),
			tx: Joi.string(),});
			},
	});

```

}

Using this it seems to recognize this line in kibana.yml  
my\_team\_plugin.tx: xxxxxxxxxxx

after the Joi has been configured how can I call the variable in js files so that edits made to the config can be implemented without re-optimization? require('./../index.js') causes an error.

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 10, 2018, 6:59pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/2 "2018-07-10T18:59:51Z")

</div>

No need to include `index.js` to access configurations. On the server, configurations are available on the server object. For example, in the APM application, configurations are accessed on the server via [server.config()](https://github.com/elastic/kibana/blob/6.3/x-pack/plugins/apm/index.js#L29)

To access configurations on the client, you must first put them into [injectDefaultVars](https://github.com/elastic/kibana/blob/6.3/x-pack/plugins/apm/index.js#L31). Then, in the UI code you can access the variables via [chrome.getInjected](https://github.com/elastic/kibana/blob/6.3/src/core_plugins/kibana/public/home/components/home_app.js#L20)

---

<div class="post-metadata">

**Author:** ![rakey](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@rakey](https://discuss.elastic.co/u/rakey)\
**Post date:** [July 10, 2018, 10:01pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/3 "2018-07-10T22:01:44Z")

</div>

Thanks for the tip, though I tried following your advice and ended up with this and it is giving me errors

export default function (kibana) {  
return new kibana.Plugin({  
id: 'my\_team\_plugin',  
uiExports: {  
docViews: ['plugins/my\_team\_plugin/team\_plugin']

```
   injectDefaultVars(server) { 
     const config = server.config(); 
     return { 
       tx: config.get('my_team_plugin.tx'), 
     }; 
   }, 
 }, 

 config(Joi) { 
   return Joi.object({ 
     enabled: Joi.boolean().default(true), 
     tx: Joi.string(), 

   }).default(); 
 }, 

```

});  
}  
if not in index.js where do I put it? That is where it is in the apm example you referenced.

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 10, 2018, 10:36pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/4 "2018-07-10T22:36:38Z")

</div>

Looks like your index.js file is not quit right. You do not have a comma after docViews. What version of kibana are you using? What is the error message?

```auto
export default function (kibana) { 
   return new kibana.Plugin({ 
     id: 'my_team_plugin', 

     uiExports: { 
       docViews: ['plugins/my_team_plugin/team_plugin'],
       injectDefaultVars(server) { 
         const config = server.config(); 
         return { 
           tx: config.get('my_team_plugin.tx'), 
         }; 
       }, 
     }, 

     config(Joi) { 
       return Joi.object({ 
         enabled: Joi.boolean().default(true), 
         tc: Joi.string(), 
       }).default(); 
     }, 
   }); 
}

```

---

<div class="post-metadata">

**Author:** ![rakey](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@rakey](https://discuss.elastic.co/u/rakey)\
**Post date:** [July 11, 2018, 12:32pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/5 "2018-07-11T12:32:16Z")

</div>

log [fatal] ValidationError: child "my\_team\_plugin" fails because ["tx" is not allowed].

Kibana 5.5.1

---

<div class="post-metadata">

**Author:** ![rakey](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@rakey](https://discuss.elastic.co/u/rakey)\
**Post date:** [July 11, 2018, 1:31pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/6 "2018-07-11T13:31:54Z")

</div>

looks like the cause of the error was that the joi string and the config.get variable were differe (which was a typo. now corrected). But chrome injector likely wont work with my environment. is there another way to load it as a variable in a way that will allow edits to take place without re-optimizing?

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 11, 2018, 1:40pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/7 "2018-07-11T13:40:58Z")

</div>

Why would chrome injector not work in your environment?

---

<div class="post-metadata">

**Author:** ![rakey](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@rakey](https://discuss.elastic.co/u/rakey)\
**Post date:** [July 12, 2018, 2:27am UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/8 "2018-07-12T02:27:47Z")

</div>

It worked. Thanks a ton for your help. you da man

---

<div class="post-metadata">

**Author:** ![protar](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@protar](https://discuss.elastic.co/u/protar)\
**Post date:** [July 13, 2018, 2:44pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/9 "2018-07-13T14:44:20Z")

</div>

This was indeed a great post buddy, would love to come back and see more such post in near future.

With Regards,  
Protar,  
[Tutuapp](https://dltutuapp.com/apk/) | [ShowBox Download](https://showbox.run/) | [Kodi](https://kodi.software/)

---

<div class="post-metadata">

**Author:** ![jaastark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaastark/32/33580_2.png) [@jaastark](https://discuss.elastic.co/u/jaastark)\
**Post date:** [July 20, 2018, 11:53am UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/10 "2018-07-20T11:53:01Z")

</div>

great post.thanks for sharing this post  
[tutuapp](http://www.tutuappapkdownloadd.com/)

---

<div class="post-metadata">

**Author:** ![frackman](https://avatars.discourse-cdn.com/v4/letter/f/67e7ee/32.png) [@frackman](https://discuss.elastic.co/u/frackman)\
**Post date:** [August 10, 2018, 9:49am UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/11 "2018-08-10T09:49:14Z")

</div>

This is a great thread where i got more information. I am bookmarking this website so that i can regularly visit this and got more and more knowledge from this [official site](https://frackmanthemovie.com/).

---

<div class="post-metadata">

**Author:** ![showbox](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@showbox](https://discuss.elastic.co/u/showbox)\
**Post date:** [August 24, 2018, 8:54am UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/12 "2018-08-24T08:54:57Z")

</div>

It works for me Thanks a ton for your help. Visit [showbox download](https://show-box.one/showbox-apk/) to get official showbox apk and stream unlimited movies and videos.

---

<div class="post-metadata">

**Author:** ![vikkimikki](https://avatars.discourse-cdn.com/v4/letter/v/a87d85/32.png) [@vikkimikki](https://discuss.elastic.co/u/vikkimikki)\
**Post date:** [August 30, 2018, 4:35pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/13 "2018-08-30T16:35:22Z")

</div>

Sounds good its works Thank You SO much [best radar detector russia](https://radrdetector.com/best-radar-detector-reviews/)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 27, 2018, 4:35pm UTC](https://discuss.elastic.co/t/make-variable-configurable-for-plugin-and-reference-in-code/139414/14 "2018-09-27T16:35:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
