Skip to content

Commit a7048de

Browse files
committed
Generalize how credentials are represented
1 parent e8816f9 commit a7048de

2 files changed

Lines changed: 17 additions & 157 deletions

File tree

open-api/rest-catalog-open-api.py

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ class AssertViewUUID(BaseModel):
467467
uuid: str
468468

469469

470+
class Credential(BaseModel):
471+
prefix: str = Field(
472+
...,
473+
description='Indicates a storage location prefix where the credential is relevant. Clients should choose the most specific prefix if several credentials of the same type are available.',
474+
)
475+
config: Dict[str, str]
476+
477+
470478
class PlanStatus(BaseModel):
471479
__root__: Literal['completed', 'submitted', 'cancelled', 'failed'] = Field(
472480
..., description='Status of a server-side planning operation'
@@ -1168,12 +1176,6 @@ class ViewUpdate(BaseModel):
11681176
]
11691177

11701178

1171-
class Credential(BaseModel):
1172-
__root__: Union[ADLSCredential, GCSCredential, S3Credential] = Field(
1173-
..., discriminator='type'
1174-
)
1175-
1176-
11771179
class LoadTableResult(BaseModel):
11781180
"""
11791181
Result used when a table is successfully loaded.
@@ -1203,8 +1205,7 @@ class LoadTableResult(BaseModel):
12031205
12041206
## Storage Credentials
12051207
1206-
Credentials for ADLS / GCS / S3 are provided through the `storage-credentials` field.
1207-
In order to avoid leaking non-expiring credentials, all credentials are required to have an expiration.
1208+
Credentials for ADLS / GCS / S3 / ... are provided through the `storage-credentials` field.
12081209
Clients should first check whether the respective credentials exist in the `storage-credentials` field before checking the `config` for credentials.
12091210
12101211
"""
@@ -1326,19 +1327,10 @@ class LoadViewResult(BaseModel):
13261327
13271328
- `token`: Authorization bearer token to use for view requests if OAuth2 security is enabled
13281329
1329-
## Storage Credentials
1330-
1331-
Credentials for ADLS / GCS / S3 are provided through the `storage-credentials` field.
1332-
In order to avoid leaking non-expiring credentials, all credentials are required to have an expiration.
1333-
Clients should first check whether the respective credentials exist in the `storage-credentials` field before checking the `config` for credentials.
1334-
13351330
"""
13361331

13371332
metadata_location: str = Field(..., alias='metadata-location')
13381333
metadata: ViewMetadata
1339-
storage_credentials: Optional[List[Credential]] = Field(
1340-
None, alias='storage-credentials'
1341-
)
13421334
config: Optional[Dict[str, str]] = None
13431335

13441336

@@ -1422,50 +1414,6 @@ class Schema(StructType):
14221414
)
14231415

14241416

1425-
class ADLSCredential(BaseModel):
1426-
type: Literal['adls']
1427-
prefix: Optional[str] = Field(
1428-
None,
1429-
description='Indicates a storage location prefix where the credential is relevant. Clients should choose the most specific prefix if several credentials of the same type are available.',
1430-
)
1431-
sas_token: str = Field(..., alias='sas-token')
1432-
expires_at_ms: int = Field(
1433-
...,
1434-
alias='expires-at-ms',
1435-
description='The epoch millis since 1970-01-01T00:00:00Z at which the given token expires',
1436-
)
1437-
1438-
1439-
class GCSCredential(BaseModel):
1440-
type: Literal['gcs']
1441-
prefix: Optional[str] = Field(
1442-
None,
1443-
description='Indicates a storage location prefix where the credential is relevant. Clients should choose the most specific prefix if several credentials of the same type are available.',
1444-
)
1445-
token: str
1446-
expires_at_ms: int = Field(
1447-
...,
1448-
alias='expires-at-ms',
1449-
description='The epoch millis since 1970-01-01T00:00:00Z at which the given token expires',
1450-
)
1451-
1452-
1453-
class S3Credential(BaseModel):
1454-
type: Literal['s3']
1455-
prefix: Optional[str] = Field(
1456-
None,
1457-
description='Indicates a storage location prefix where the credential is relevant. Clients should choose the most specific prefix if several credentials of the same type are available.',
1458-
)
1459-
access_key_id: str = Field(..., alias='access-key-id')
1460-
secret_access_key: str = Field(..., alias='secret-access-key')
1461-
session_token: str = Field(..., alias='session-token')
1462-
expires_at_ms: int = Field(
1463-
...,
1464-
alias='expires-at-ms',
1465-
description='The epoch millis since 1970-01-01T00:00:00Z at which the given token expires',
1466-
)
1467-
1468-
14691417
class CompletedPlanningResult(ScanTasks):
14701418
"""
14711419
Completed server-side planning result
@@ -1498,16 +1446,12 @@ class CompletedPlanningWithIDResult(CompletedPlanningResult):
14981446
TableMetadata.update_forward_refs()
14991447
ViewMetadata.update_forward_refs()
15001448
AddSchemaUpdate.update_forward_refs()
1501-
Credential.update_forward_refs()
15021449
ScanTasks.update_forward_refs()
15031450
FetchPlanningResult.update_forward_refs()
15041451
PlanTableScanResult.update_forward_refs()
15051452
CreateTableRequest.update_forward_refs()
15061453
CreateViewRequest.update_forward_refs()
15071454
ReportMetricsRequest.update_forward_refs()
1508-
ADLSCredential.update_forward_refs()
1509-
GCSCredential.update_forward_refs()
1510-
S3Credential.update_forward_refs()
15111455
CompletedPlanningResult.update_forward_refs()
15121456
FetchScanTasksResult.update_forward_refs()
15131457
CompletedPlanningWithIDResult.update_forward_refs()

open-api/rest-catalog-open-api.yaml

Lines changed: 8 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,94 +3103,21 @@ components:
31033103
uuid:
31043104
type: string
31053105

3106-
ADLSCredential:
3107-
type: object
3108-
allOf:
3109-
- $ref: '#/components/schemas/Credential'
3110-
required:
3111-
- type
3112-
- sas-token
3113-
- expires-at-ms
3114-
properties:
3115-
type:
3116-
type: string
3117-
enum: [ "adls" ]
3118-
prefix:
3119-
type: string
3120-
description: Indicates a storage location prefix where the credential is relevant. Clients should choose the most
3121-
specific prefix if several credentials of the same type are available.
3122-
sas-token:
3123-
type: string
3124-
expires-at-ms:
3125-
type: integer
3126-
format: int64
3127-
description: The epoch millis since 1970-01-01T00:00:00Z at which the given token expires
3128-
3129-
3130-
GCSCredential:
3131-
type: object
3132-
allOf:
3133-
- $ref: '#/components/schemas/Credential'
3134-
required:
3135-
- type
3136-
- token
3137-
- expires-at-ms
3138-
properties:
3139-
type:
3140-
type: string
3141-
enum: [ "gcs" ]
3142-
prefix:
3143-
type: string
3144-
description: Indicates a storage location prefix where the credential is relevant. Clients should choose the most
3145-
specific prefix if several credentials of the same type are available.
3146-
token:
3147-
type: string
3148-
expires-at-ms:
3149-
type: integer
3150-
format: int64
3151-
description: The epoch millis since 1970-01-01T00:00:00Z at which the given token expires
3152-
3153-
S3Credential:
3106+
Credential:
31543107
type: object
3155-
allOf:
3156-
- $ref: '#/components/schemas/Credential'
31573108
required:
3158-
- type
3159-
- access-key-id
3160-
- secret-access-key
3161-
- session-token
3162-
- expires-at-ms
3109+
- prefix
3110+
- config
31633111
properties:
3164-
type:
3165-
type: string
3166-
enum: [ "s3" ]
31673112
prefix:
31683113
type: string
31693114
description: Indicates a storage location prefix where the credential is relevant. Clients should choose the most
31703115
specific prefix if several credentials of the same type are available.
3171-
access-key-id:
3172-
type: string
3173-
secret-access-key:
3174-
type: string
3175-
session-token:
3176-
type: string
3177-
expires-at-ms:
3178-
type: integer
3179-
format: int64
3180-
description: The epoch millis since 1970-01-01T00:00:00Z at which the given token expires
3116+
config:
3117+
type: object
3118+
additionalProperties:
3119+
type: string
31813120

3182-
Credential:
3183-
type: object
3184-
discriminator:
3185-
propertyName: type
3186-
mapping:
3187-
adls: '#/components/schemas/ADLSCredential'
3188-
gcs: '#/components/schemas/GCSCredential'
3189-
s3: '#/components/schemas/S3Credential'
3190-
oneOf:
3191-
- $ref: '#/components/schemas/ADLSCredential'
3192-
- $ref: '#/components/schemas/GCSCredential'
3193-
- $ref: '#/components/schemas/S3Credential'
31943121

31953122
LoadTableResult:
31963123
description: |
@@ -3221,8 +3148,7 @@ components:
32213148
32223149
## Storage Credentials
32233150
3224-
Credentials for ADLS / GCS / S3 are provided through the `storage-credentials` field.
3225-
In order to avoid leaking non-expiring credentials, all credentials are required to have an expiration.
3151+
Credentials for ADLS / GCS / S3 / ... are provided through the `storage-credentials` field.
32263152
Clients should first check whether the respective credentials exist in the `storage-credentials` field before checking the `config` for credentials.
32273153
type: object
32283154
required:
@@ -3493,12 +3419,6 @@ components:
34933419
## General Configurations
34943420
34953421
- `token`: Authorization bearer token to use for view requests if OAuth2 security is enabled
3496-
3497-
## Storage Credentials
3498-
3499-
Credentials for ADLS / GCS / S3 are provided through the `storage-credentials` field.
3500-
In order to avoid leaking non-expiring credentials, all credentials are required to have an expiration.
3501-
Clients should first check whether the respective credentials exist in the `storage-credentials` field before checking the `config` for credentials.
35023422
type: object
35033423
required:
35043424
- metadata-location
@@ -3508,10 +3428,6 @@ components:
35083428
type: string
35093429
metadata:
35103430
$ref: '#/components/schemas/ViewMetadata'
3511-
storage-credentials:
3512-
type: array
3513-
items:
3514-
$ref: '#/components/schemas/Credential'
35153431
config:
35163432
type: object
35173433
additionalProperties:

0 commit comments

Comments
 (0)