Check for session validity/expected timeout?

CamJNCamJN
in CLI

Previously (pre 1.0) I could check if there was a valid session, and work out when it would time out like this:

function getoplimit {
    shopt -s nullglob;
    for file in $TMPDIR/com.agilebits.op.`id -u`/.??*; do
        jsq accessed < $file
    done | \
        sed -Ee 's/\.[0-9]{4,}//g' -e 's/"//g' -e 's/([-+][0-9]{2}):([0-9]{2})/\1\2/g' | \
        while read date; do
            date -jf "%FT%T%z" -v+30m "$date" "+%s"
        done | \
            max
}

Now the accessed field is gone, and I am left wondering if decoding the file contents would tell me what I want (it seems to be some kind of jwe encoded data?), or if there's a better way to find this?


1Password Version: cli 1.0.0
Extension Version: Not Provided
OS Version: 10.15.4
Sync Type: Not Provided

Comments

  • felix_1pfelix_1p

    Team Member

    Hi @CamJN ! We had to change this because when multiple op processes ran in parallel, they would potentially update the session file at the same time which could result in corrupt JSON data. Apparently cross-platform file locking isn't straightforward.

    So instead we just directly update the last modified time of the file via platform specific system calls. So getting the modification time via ls might work?

    However, I think we should either add a command to check the existence or a session or use a specific exist code to indicate that no session is available (for a specific account at least).

  • Ah gotcha, so the file modification time should be reasonably reliable as a "last accessed" timestamp. I can work with that for now.

  • BenBen AWS Team

    Team Member

    Hey @CamJN

    Were you able to make progress with this? Wondering how it worked out. :)

    Ben

  • I updated the function as follows:

    function getoplimit {
        shopt -s nullglob;
        for file in $TMPDIR/com.agilebits.op.`id -u`/.??*; do
            stat -t '%s' -f '%Sm' "$file"
        done | while read date; do
            date -jf "%s" -v+30M "$date" "+%s"
        done | max 2>/dev/null
    }
    

    Seems to work.

  • BenBen AWS Team

    Team Member

    Great! Thanks for the update. :)

    Ben

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file