Make the displayed SSH username configurable #12
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "mirsal/capsul-flask:ssh-username"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This patch allows the SSH username displayed in templates to be
configured through the SSH_USERNAME environment variable.
LGTM! Maybe one stylistic change, we could potentially fix that after. @forest over to you 👌
@ -98,3 +98,3 @@
<div class="row justify-start">
<label class="align" for="ssh_username">SSH Username</label>
<span id="ssh_username">cyberian</span>
<span id="ssh_username">{{ config.SSH_USERNAME | default('cyberian') }}</span>
I think @forest was saying he preferred that templates not be dependent on the structure of the config, so setting a context variable in the view as here: https://git.autonomic.zone/3wordchant/capsul-flask/src/branch/master/capsulflask/console.py#L429
it can be done that way, although there are many calls to render_template() and so adding a context variable to each of them would be error-prone and require many more changes.
@forest would you rather have it passed through the context every time?
hmm.. I don't think it's any more error prone than putting the
config.SSH_USERNAME
into the template. I have been hurt by template engines too many times and I tend to try to isolate and validate all inputs into the template before I execute it. In the past, I've encountered template engines that fail silently, or fail with a meaningless error (there is no stack trace inside the template, inside the template no one can hear you scream).TBH I did not know that it was even possible to reach into a global
config
object from within the template. In my mental model, the only thing you can access from within the template is exactly what is directly passed to it. Obviously thats not true in flask, but if I could make it true, I would. When dealing with error-prone things that do not always provide good error messages, having a comprehensive inventory of all the moving parts in one place helps a lot.I think it would help developers debug templates easier if they could simply inspect the data object that gets passed to the template right before it is executed, either through print debugging (
logger.debug(object_to_json_string(data_object))
) or with a property inspector in a proper debugger.I guess I believe that its the same error-prone, duplicate code problem either way, but I am strongly biased against template engines and I want to put them all in diapers, even though I don't have enough experience with jinja2 to know for sure if it needs that kind of treatment.
Is this silly? Am I wrong? I don't know. I have been doing it one way and I'm resistant to change 😳
That's definitely not silly and I do not believe that you are wrong (I think that it is safe in that specific case but it would not be obvious to future contributors)
I'm sending another patch which uses the
vm
context object instead of adding a new context variable, so we get the best of both worlds ;)@ -23,3 +23,2 @@
How do I log in?
<p>ssh to the ip provided to you using the cyberian user.</p>
<pre class='code'>$ ssh cyberian@1.2.3.4</pre>
<p>ssh to the ip provided to you using the "{{ config.SSH_USERNAME | default('cyberian') }}" user.</p>
As above
837660aad9
tod4a9f2f40a
👍
Love this. Maybe there should be a linked set of changes to modify the capsul-images repo in order to produce images with the given username as well. Otherwise this all LGTM!