Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ FLOWCV_COOKIE=flowcvsidapp=s%3A... # your session cookie, OR
- **Resume id** is optional: with one resume it's auto-selected; with several,
set `FLOWCV_RESUME_ID` or pass `--resume-id <id>` (run `flowcv resumes` to list).

### Multiple accounts and Google sign-in

FlowCV accounts created through Google do not have a FlowCV password for the
`login` endpoint. Add their existing browser session cookie instead. The prompt
is hidden, so the cookie is not stored in shell history:

```console
flowcv account add gmail --use
# paste either the flowcvsidapp value or a full Cookie header when prompted
flowcv account add qq
flowcv account list
flowcv account use gmail
flowcv --account qq resumes
```

Find `flowcvsidapp` after signing into the desired account in the browser:
DevTools → Application → Cookies → `https://app.flowcv.com`. Each named account
has isolated credentials and session state under the FlowCV CLI config folder.

To copy a resume between accounts:

```console
flowcv --account gmail resumes
flowcv transfer --from gmail --to qq --resume-id SOURCE_ID --title "Imported CV"
```

The transfer creates a new resume in the destination account and leaves the
source unchanged. FlowCV plan limits still apply.

## CLI

```bash
Expand Down
89 changes: 82 additions & 7 deletions flowcvcli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""
import argparse
import datetime
import getpass
import json
import os
import re
Expand All @@ -29,7 +30,8 @@
from .api import FlowCV
from .client import login as do_login, _write_session, _jar_header
from .config import (Config, dotenv_files_found, resolve_auth_source,
session_file_info)
session_file_info, list_accounts, load_account, save_account,
use_account, remove_account, selected_account)
from .errors import FlowCVError
from .content import SECTION_META, label_of, rich_field
from .jsonresume import from_jsonresume, to_jsonresume
Expand Down Expand Up @@ -110,18 +112,72 @@ def _result(env, label):


def _fc(a):
return FlowCV(resume_id=getattr(a, "resume_id_override", None))
cfg = Config.load(account=getattr(a, "account_override", None))
return FlowCV(config=cfg, resume_id=getattr(a, "resume_id_override", None))


# ------------------------------------------------------------------ commands
def cmd_login(a):
fc = _fc(a)
if not (fc.cfg.email and fc.cfg.password):
sys.exit("Set FLOWCV_EMAIL and FLOWCV_PASSWORD in .env to use `login`.")
_write_session(_jar_header(do_login(fc.cfg.email, fc.cfg.password)))
_write_session(_jar_header(do_login(fc.cfg.email, fc.cfg.password)), fc.cfg.session_file)
_emit({"success": True}, lambda: print("login ok -> session cached to .flowcv_session"))


def cmd_account_add(a):
cookie = getpass.getpass("FlowCV Cookie (hidden; include flowcvsidapp=): ")
path = save_account(a.name, cookie=cookie, resume_id=a.resume_id)
if a.use:
use_account(a.name)
_emit({"success": True, "account": a.name, "selected": bool(a.use)},
lambda: print(f"saved account {a.name!r} -> {path}" + (" (selected)" if a.use else "")))


def cmd_account_migrate(a):
"""Save the currently configured legacy login/session as a named account."""
cfg = Config.load()
cookie = FlowCV(config=cfg).cookie()
save_account(a.name, cookie=cookie, resume_id=a.resume_id or cfg.resume_id)
if a.use:
use_account(a.name)
_emit({"success": True, "account": a.name, "selected": bool(a.use)},
lambda: print(f"saved current login as account {a.name!r}" +
(" (selected)" if a.use else "")))


def cmd_account_list(a):
names = list_accounts()
current = selected_account()
rows = [{"name": n, "current": n == current,
"resume_id": load_account(n).get("resume_id")} for n in names]
_emit(rows, lambda: [print(("* " if r["current"] else " ") + r["name"])
for r in rows])


def cmd_account_use(a):
use_account(a.name)
_emit({"success": True, "account": a.name}, lambda: print(f"using account {a.name!r}"))


def cmd_account_remove(a):
remove_account(a.name)
_emit({"success": True, "account": a.name}, lambda: print(f"removed account {a.name!r}"))


def cmd_transfer(a):
"""Copy a resume between two named accounts without printing its contents."""
src = FlowCV(config=Config.load(account=a.from_account),
resume_id=getattr(a, "resume_id_override", None))
dst = FlowCV(config=Config.load(account=a.to_account))
resume = src.export_resume()
new_id = dst.import_resume(resume, title=a.title)
data = {"success": True, "from": a.from_account, "to": a.to_account,
"source_resume_id": resume.get("id"), "new_resume_id": new_id}
_emit(data, lambda: print(f"copied {resume.get('title') or 'resume'}: "
f"{a.from_account} -> {a.to_account} ({new_id})"))


def cmd_resumes(a):
resumes = _fc(a).list_resumes()

Expand Down Expand Up @@ -583,8 +639,8 @@ def _doctor_env_cookie_check(cfg):
"full name=value pair from DevTools, not just the value")


def _doctor_session_check():
info = session_file_info()
def _doctor_session_check(cfg=None):
info = session_file_info(cfg.session_file if cfg else None)
path = info["path"]
if not info["exists"]:
return _check("session file", None, f"no cached session ({path})")
Expand Down Expand Up @@ -620,11 +676,11 @@ def _doctor_live_check(a, offline):


def cmd_doctor(a):
cfg = Config.load()
cfg = Config.load(account=getattr(a, "account_override", None))
source = resolve_auth_source(cfg)
checks = [_doctor_auth_check(cfg, source),
_doctor_env_cookie_check(cfg),
_doctor_session_check(),
_doctor_session_check(cfg),
_doctor_curl_cffi_check(source),
_doctor_live_check(a, a.offline)]
ok = all(c["ok"] is not False for c in checks) # skipped (None) never fails
Expand Down Expand Up @@ -652,6 +708,8 @@ def build_parser():
# BEFORE the subcommand (same issue as --json; read via getattr).
common.add_argument("--resume-id", dest="resume_id_override",
default=argparse.SUPPRESS, help="target a specific resume")
common.add_argument("--account", dest="account_override", default=argparse.SUPPRESS,
help="use a named FlowCV account for this command")
# default=SUPPRESS so this shared flag works BEFORE or AFTER the subcommand:
# a plain default would be re-applied by the subparser and clobber a value the
# top-level parser already set (read via getattr(args, "json", False)).
Expand All @@ -666,7 +724,24 @@ def add(name, **kw):
return sub.add_parser(name, parents=[common], **kw)

add("login").set_defaults(fn=cmd_login)
s = add("account", description="Manage named FlowCV accounts (cookies are stored locally with owner-only permissions).")
account_sub = s.add_subparsers(dest="account_cmd", required=True)
x = account_sub.add_parser("add"); x.add_argument("name"); x.add_argument("--resume-id")
x.add_argument("--use", action="store_true", help="select this account after saving")
x.set_defaults(fn=cmd_account_add)
x = account_sub.add_parser("migrate", help="save the current legacy login/session as a named account")
x.add_argument("name"); x.add_argument("--resume-id")
x.add_argument("--use", action="store_true", help="select this account after saving")
x.set_defaults(fn=cmd_account_migrate)
x = account_sub.add_parser("list"); x.set_defaults(fn=cmd_account_list)
x = account_sub.add_parser("use"); x.add_argument("name"); x.set_defaults(fn=cmd_account_use)
x = account_sub.add_parser("remove"); x.add_argument("name"); x.set_defaults(fn=cmd_account_remove)
add("resumes").set_defaults(fn=cmd_resumes)
s = add("transfer", description="Copy a resume from one named account into another account.")
s.add_argument("--from", dest="from_account", required=True, help="source account name")
s.add_argument("--to", dest="to_account", required=True, help="destination account name")
s.add_argument("--title", help="title of the new resume in the destination account")
s.set_defaults(fn=cmd_transfer)

s = add("new"); s.add_argument("title"); s.set_defaults(fn=cmd_new)
s = add("duplicate"); s.add_argument("title", nargs="?"); s.set_defaults(fn=cmd_duplicate)
Expand Down
25 changes: 15 additions & 10 deletions flowcvcli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@ def login(email, password, jar=None):
return jar


def _write_session(cookie):
def _write_session(cookie, path=None):
"""Persist the session cookie header with owner-only perms (0o600) — it's a credential."""
parent = os.path.dirname(SESSION_FILE)
path = path or Config.load().session_file
parent = os.path.dirname(path)
if parent:
os.makedirs(parent, exist_ok=True)
fd = os.open(SESSION_FILE, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
with os.fdopen(fd, "w") as f:
f.write(cookie)

Expand All @@ -258,6 +259,10 @@ def __init__(self, config=None, resume_id=None):
self._batch_depth = 0 # >0 while inside batch(): get_resume() is cached
self._batch_cache = None # the one fetched resume shared across a batch

def _session_path(self):
"""Keep the legacy session path patchable while isolating named accounts."""
return self.cfg.session_file if self.cfg.account else SESSION_FILE

# ---- auth -------------------------------------------------------------
def _ensure_auth(self):
"""Seed the cookie jar once, in priority order: FLOWCV_COOKIE (env) ->
Expand All @@ -273,8 +278,8 @@ def _ensure_auth(self):
"(FLOWCV_COOKIE=flowcvsidapp=s%3A...), not just the value.")
self._authed = True
return
if os.path.exists(SESSION_FILE):
with open(SESSION_FILE) as f:
if os.path.exists(self._session_path()):
with open(self._session_path()) as f:
cached = f.read().strip()
if cached:
_seed_jar(self._jar, cached)
Expand All @@ -297,7 +302,7 @@ def cookie(self):

def _persist(self):
header = _jar_header(self._jar)
_write_session(header)
_write_session(header, self._session_path())
self._persisted = header

def _maybe_persist(self):
Expand All @@ -307,7 +312,7 @@ def _maybe_persist(self):
return
header = _jar_header(self._jar)
if header and header != self._persisted:
_write_session(header)
_write_session(header, self._session_path())
self._persisted = header

def relogin(self):
Expand All @@ -319,7 +324,7 @@ def relogin(self):
if not (self.cfg.email and self.cfg.password):
return False
try:
os.remove(SESSION_FILE)
os.remove(self._session_path())
except OSError:
pass
self._jar.clear()
Expand Down Expand Up @@ -391,8 +396,8 @@ def _auth_rescues(self):
When the seed was a stale FLOWCV_COOKIE, the cached session file written
by an earlier login is often still valid, so it is tried before a login.
"""
if self.cfg.cookie and os.path.exists(SESSION_FILE):
with open(SESSION_FILE) as f:
if self.cfg.cookie and os.path.exists(self._session_path()):
with open(self._session_path()) as f:
cached = f.read().strip()
if cached and cached != _jar_header(self._jar):
self._jar.clear()
Expand Down
Loading