Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Expire time as ISO 8601 #217

Open
snago opened this issue Jan 21, 2020 · 3 comments
Open

[FEATURE] Expire time as ISO 8601 #217

snago opened this issue Jan 21, 2020 · 3 comments

Comments

@snago
Copy link

snago commented Jan 21, 2020

Is your feature request related to a problem?

As a human, looking at users pillars it is hard to see when they expire.

Describe the solution you'd like

Instead of this:

    expire: 1594548000

I would like to be able to have this:

    expire: 2020-07-12T10:00:00Z

Describe alternatives you've considered

Augment my brain with a chip that automatically can convert numbers I see from UNIX timestamp and insert the date and time as a memory. E.g. I would look at a UNIX timestamp and think of the first time that I ate asparagus and I would "remember" that it was 2020-07-12 at 10:00:00.
That would be much cooler, but it seems a lot harder.

Additional context

@myii
Copy link
Member

myii commented Jan 26, 2020

@snago Sorry to hear that asparagus doesn't do it for you!

The issue here is deeper than this formula. It uses Salt's user.present state, which expects the value to be given in days.

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.user.html#salt.states.user.present

expire
Date that account expires, represented in days since epoch (January 1, 1970).

It wouldn't be a good idea to try to resolve this in the formula using even more Jinja than there already is:

{% if 'expire' in user -%}
{% if grains['kernel'].endswith('BSD') and
user['expire'] < 157766400 %}
{# 157762800s since epoch equals 01 Jan 1975 00:00:00 UTC #}
- expire: {{ user['expire'] * 86400 }}
{% elif grains['kernel'] == 'Linux' and
user['expire'] > 84006 %}
{# 2932896 days since epoch equals 9999-12-31 #}
- expire: {{ (user['expire'] / 86400) | int }}
{% else %}
- expire: {{ user['expire'] }}
{% endif %}
{% endif -%}

Your best bet is to file an issue in the main SaltStack repo and see what their response is.

In the meantime, you could build upon an answer such as this one to use this expression to calculate a given date. So something like:

$ expr $(date -d "2020-01-01" +%s) / 86400
18262

@snago
Copy link
Author

snago commented Jan 27, 2020

Ah, yes, you are right. It would be much better to fix this in user.present.

I've opened saltstack/salt#55983.

But looking at that jinja it looks like when/if that issue is fixed and user.present accepts strings as expire there might be some changes required to this formula before I could start using strings as expire in the users pillars.

@myii
Copy link
Member

myii commented Jan 27, 2020

I've opened saltstack/salt#55983.

@snago Excellent, hope that leads to a resolution and doesn't fall afoul of the dreaded stalebot!

But looking at that jinja it looks like when/if that issue is fixed and user.present accepts strings as expire there might be some changes required to this formula before I could start using strings as expire in the users pillars.

Now this might sound strange but our formulas don't benefit from upstream changes immediately. The problem is that we have to remain backwards compatible with all of the officially supported releases, so that goes back to 2018.3 at the current time. Have a look at our Travis runs for a clearer picture:

We do test against the master branch, though, so if this feature is ever implemented, we could add another conditional to the current code to take advantage of that. It could be some time before that happens, though. Unless someone steps up to provide a PR to implement the feature...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants