Code Monkey home page Code Monkey logo

Comments (1)

Nick2253 avatar Nick2253 commented on July 3, 2024

As I'm working through this, a couple more notes of issues and how I'm attempting to solve them. Any feedback on these approaches would be useful. I should have the pull request ready in the next week or so.

Empty Strings

One of the main keys in MeshCentral is the empty string domain key: "domains": { "": { ... } }. We need a way to represent this key that avoids ambiguity with other possible keys. In Gitea, they use the form _0Xaa_ to represent ASCII characters that aren't legal environment variable characters, where aa is the two letter ASCII code. For example, in Gitea, the key ui.admin has the period character, which is not a legal character in environment variables. As such, that key is represented as ui_0X46_admin.

For the empty string, we can use the null character 0X00. This would be a special interpretation, but is fairly sensical, and works well. That means our key "domains": {"": {"title": ...} } would be something like: MC__domains___0X00___title. Note the three underscores: that's two underscores, indicating a level, and the third underscore for the wrapper on the ASCII character code.

Case Sensitivity

I'm not sure if MeshCentral requires case sensitive keys in the config file, but fortunately, environment variables do not require upper case (it is merely by convention that environment variables are all upper-case). As such, values can be rendered exactly as they are in the name. For example, MC__domains would be "domains" and MC__DoMaInS would be "DoMaInS".

This also means that it's not trivial to check for case errors in the environment variables. My approach here is to simply assume the user is casing everything correctly, and blindly incorporate that into the config.json file.

_Keys (removed config keys)

By convention, Javascript uses _ in front of a name to indicate that it's private. In MeshCentral, we use this convention in the config file to "remove" a variable so that it is not applied in the config.

We can use a special value of _ to indicate that a variable should be disabled. For example, MC__domains=_ would cause the existing "domains": { ... } key to be replaced with a "_domains": { ... } key, preserving the existing value under this new _ key.

We can also recognize empty environment variables, and set the value to the empty string. For example, MC__domains= will preserve the "domains" key, but set the value to "", like: "domains": "".

Other Thoughts

This concept was mentioned in #22, so I would hope there's some interest in this setup. In that thread, two tools were suggested that can perform this action using Javascript/Typescript. That may be a better approach to this problem, but I'm woefully unskilled in either of those two languages, so I'm sticking with Shell for this.

After looking through the Dockerfile, I realized that python3 is currently installed as part of the container, which would make Python a first-class citizen in MeshCentral. However, I'm not convinced that Python is actually a requirement for MeshCentral, since I found mentions only in a few workflow pieces, and nothing in the actual code-base. It would seem that python3 is an unnecessary package for the container, and should be removed. As such, I'll hold off on a Python version of this until I hear otherwise that Python is going to stick around.

from meshcentral.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.