Move login/logout into the generic dispatcher #2

Open
opened 2026-05-16 10:02:00 +02:00 by heiko · 1 comment
Owner

Plan 5: Move login/logout into the generic dispatcher

Goal

login and logout appear in ListAPICalls() and work like every other command.
Remove the special-case if cmd == "login" block in run().

Schema changes (dmapi/api.yaml)

Add a new top-level boolean field auth-required (defaults to true).
Set it to false on login and logout.

- endpoint:
    path: login
  auth-required: false
  params:
    api-key:
      type: string
      required: true
  result:
    LoginResult:

- endpoint:
    path: logout
  auth-required: false
  result:
    BasicResult:

Generator changes (dmapi/gen/main.go + dmapi/api.go.template)

  • Add AuthRequired bool to the model struct (default true).
  • Emit AuthRequired bool on APICall struct.
  • Template: set APICall.AuthRequired from the YAML field.

Runtime changes (dmapi/request.go / dmapi/client.go)

  • Client.Do checks APICall.AuthRequired; if false, skip cookie restore and
    the re-login retry loop.
  • Move Login result handling (print "login ok") into run() after the generic
    io.Copy, or let LoginResult body carry the TLD list.

LoginResult type

Currently defined by hand in login.go. Once the generator can emit it, the hand-
written type can be removed. Until then, the generated code can embed it by name
(LoginResult: in the result: map — same pattern as BasicResult:).

Notes

  • client.Login() stays as a direct method used internally for re-auth on 401.
    The generic dispatcher calls client.Do() which in turn calls client.Login()
    on session expiry — so there is no circular dependency.
  • logout just needs BasicResult; no extra fields.
# Plan 5: Move login/logout into the generic dispatcher ## Goal `login` and `logout` appear in `ListAPICalls()` and work like every other command. Remove the special-case `if cmd == "login"` block in `run()`. ## Schema changes (`dmapi/api.yaml`) Add a new top-level boolean field `auth-required` (defaults to true). Set it to `false` on `login` and `logout`. ```yaml - endpoint: path: login auth-required: false params: api-key: type: string required: true result: LoginResult: - endpoint: path: logout auth-required: false result: BasicResult: ``` ## Generator changes (`dmapi/gen/main.go` + `dmapi/api.go.template`) - Add `AuthRequired bool` to the `model` struct (default true). - Emit `AuthRequired bool` on `APICall` struct. - Template: set `APICall.AuthRequired` from the YAML field. ## Runtime changes (`dmapi/request.go` / `dmapi/client.go`) - `Client.Do` checks `APICall.AuthRequired`; if false, skip cookie restore and the re-login retry loop. - Move `Login` result handling (print "login ok") into `run()` after the generic `io.Copy`, or let `LoginResult` body carry the TLD list. ## `LoginResult` type Currently defined by hand in `login.go`. Once the generator can emit it, the hand- written type can be removed. Until then, the generated code can embed it by name (`LoginResult:` in the `result:` map — same pattern as `BasicResult:`). ## Notes - `client.Login()` stays as a direct method used internally for re-auth on 401. The generic dispatcher calls `client.Do()` which in turn calls `client.Login()` on session expiry — so there is no circular dependency. - `logout` just needs `BasicResult`; no extra fields.
Author
Owner

AI attribution comment added per repository instruction for this open issue.\n\n(co)authored by ai:gpt-5-codex

AI attribution comment added per repository instruction for this open issue.\n\n(co)authored by ai:gpt-5-codex
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
IUS/joker-dmapi-client#2
No description provided.