Coverage for /builds/BuildGrid/buildgrid/buildgrid/cleanup/janitor/config.py: 89.66%

29 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-06-11 15:37 +0000

1# Copyright (C) 2024 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15 

16import os 

17from typing import Optional, Union 

18 

19from pydantic import BaseModel, Field 

20 

21from buildgrid._app.settings.parser import get_parser 

22 

23 

24class S3Config(BaseModel): 

25 access_key: str 

26 bucket_regex: str 

27 endpoint: str 

28 path_prefix: str 

29 hash_prefix_size: int = Field(default=0) 

30 secret_key: str 

31 

32 

33class RedisConfig(BaseModel): 

34 db: Optional[int] = Field(default=None) 

35 dns_srv_record: Optional[str] = Field(default=None) 

36 index_prefix: str 

37 key_batch_size: int 

38 password: Optional[str] = Field(default=None) 

39 host: Optional[str] = Field(default=None) 

40 port: Optional[int] = Field(default=None) 

41 sentinel_master_name: Optional[str] = Field(default=None) 

42 

43 

44class JanitorConfig(BaseModel): 

45 redis: Optional[RedisConfig] = Field(default=None) 

46 sleep_interval: int 

47 s3: S3Config 

48 sql_connection_string: Optional[str] = Field(default=None) 

49 

50 

51def parse_janitor_config(path: Union[str, bytes, "os.PathLike[str]"]) -> JanitorConfig: 

52 with open(path) as config_file: 

53 # NOTE: get_parser is untyped, it returns a modified version of the `yaml` module 

54 config = get_parser().safe_load(config_file) # type: ignore 

55 return JanitorConfig(**config)