Skip to content

Commit

Permalink
config: Add support for auth.client-id
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarnett committed Sep 15, 2024
1 parent 4dcc084 commit b891a48
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
22 changes: 22 additions & 0 deletions data/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
"description": "User configuration for gcalcli command-line tool.\n\nSee https://pypi.org/project/gcalcli/.",
"type": "object",
"$defs": {
"AuthSection": {
"title": "Settings for authentication",
"type": "object",
"properties": {
"client-id": {
"title": "Client ID for Google auth token",
"description": "Google client ID for your auth client project.\n\nDetails: https://github.com/insanum/gcalcli/blob/HEAD/docs/api-auth.md",
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null
}
}
},
"CalendarsSection": {
"title": "Settings about the set of calendars gcalcli operates on",
"type": "object",
Expand Down Expand Up @@ -45,6 +64,9 @@
}
},
"properties": {
"auth": {
"$ref": "#/$defs/AuthSection"
},
"calendars": {
"$ref": "#/$defs/CalendarsSection"
},
Expand Down
26 changes: 24 additions & 2 deletions gcalcli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import OrderedDict
from enum import Enum
import sys
from typing import Any, List, Mapping
from typing import Any, List, Mapping, Optional

if sys.version_info[:2] < (3, 11):
import toml as tomllib
Expand All @@ -15,6 +15,24 @@
from pydantic.json_schema import GenerateJsonSchema


class AuthSection(BaseModel):
"""Configuration for settings like client-id used in auth flow.
Note that client-secret can't be configured here and should be passed on
command-line instead for security reasons.
"""

model_config = ConfigDict(title='Settings for authentication')

client_id: Optional[str] = Field(
alias='client-id',
title='Client ID for Google auth token',
description="""Google client ID for your auth client project.\n
Details: https://github.com/insanum/gcalcli/blob/HEAD/docs/api-auth.md""",
default=None,
)


class CalendarsSection(BaseModel):
model_config = ConfigDict(
title='Settings about the set of calendars gcalcli operates on'
Expand Down Expand Up @@ -48,7 +66,8 @@ class OutputSection(BaseModel):
week_start: WeekStart = Field(
alias='week-start',
title='Weekday to treat as start of week',
default=WeekStart.SUNDAY)
default=WeekStart.SUNDAY,
)


class Config(BaseModel):
Expand All @@ -62,6 +81,7 @@ class Config(BaseModel):
json_schema_extra={'$schema': GenerateJsonSchema.schema_dialect},
)

auth: AuthSection = Field(default_factory=AuthSection)
calendars: CalendarsSection = Field(default_factory=CalendarsSection)
output: OutputSection = Field(default_factory=OutputSection)

Expand All @@ -72,6 +92,8 @@ def from_toml(cls, config_file):

def to_argparse_namespace(self) -> argparse.Namespace:
kwargs = {}
if self.auth:
kwargs.update(vars(self.auth))
if self.calendars:
kwargs.update(vars(self.calendars))
if self.output:
Expand Down

0 comments on commit b891a48

Please sign in to comment.