postgresql-charms-single-kernel 16.0.2__tar.gz → 16.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (15) hide show
  1. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/PKG-INFO +1 -1
  2. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/postgresql_charms_single_kernel.egg-info/PKG-INFO +1 -1
  3. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/pyproject.toml +2 -2
  4. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/abstract_charm.py +2 -1
  5. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/config/literals.py +9 -0
  6. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/utils/postgresql.py +23 -3
  7. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/README.md +0 -0
  8. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/postgresql_charms_single_kernel.egg-info/SOURCES.txt +0 -0
  9. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/postgresql_charms_single_kernel.egg-info/dependency_links.txt +0 -0
  10. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/postgresql_charms_single_kernel.egg-info/top_level.txt +0 -0
  11. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/setup.cfg +0 -0
  12. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/__init__.py +0 -0
  13. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/config/__init__.py +0 -0
  14. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/utils/__init__.py +0 -0
  15. {postgresql_charms_single_kernel-16.0.2 → postgresql_charms_single_kernel-16.1.0}/single_kernel_postgresql/utils/filesystem.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: postgresql-charms-single-kernel
3
- Version: 16.0.2
3
+ Version: 16.1.0
4
4
  Summary: Shared and reusable code for PostgreSQL-related charms
5
5
  Author-email: Canonical Data Platform <data-platform@lists.launchpad.net>
6
6
  License-Expression: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: postgresql-charms-single-kernel
3
- Version: 16.0.2
3
+ Version: 16.1.0
4
4
  Summary: Shared and reusable code for PostgreSQL-related charms
5
5
  Author-email: Canonical Data Platform <data-platform@lists.launchpad.net>
6
6
  License-Expression: Apache-2.0
@@ -4,7 +4,7 @@
4
4
  [project]
5
5
  name = "postgresql-charms-single-kernel"
6
6
  description = "Shared and reusable code for PostgreSQL-related charms"
7
- version = "16.0.2"
7
+ version = "16.1.0"
8
8
  readme = "README.md"
9
9
  license = "Apache-2.0"
10
10
  authors = [
@@ -23,7 +23,7 @@ lib = [
23
23
  "psycopg2>=2.9.10",
24
24
  ]
25
25
  format = [
26
- "ruff==0.13.1"
26
+ "ruff==0.13.2"
27
27
  ]
28
28
  lint = [
29
29
  "codespell==2.4.1",
@@ -4,7 +4,7 @@
4
4
 
5
5
  from ops.charm import CharmBase
6
6
 
7
- from .config.literals import SYSTEM_USERS, USER
7
+ from .config.literals import SYSTEM_USERS, USER, Substrates
8
8
  from .utils.postgresql import PostgreSQL
9
9
 
10
10
 
@@ -15,6 +15,7 @@ class AbstractPostgreSQLCharm(CharmBase):
15
15
  super().__init__(*args)
16
16
 
17
17
  self.postgresql = PostgreSQL(
18
+ substrate=Substrates.VM,
18
19
  primary_host="localhost",
19
20
  current_host="localhost",
20
21
  user=USER,
@@ -5,6 +5,8 @@
5
5
  This module should contain the literals used in the charms (paths, enums, etc).
6
6
  """
7
7
 
8
+ from enum import Enum
9
+
8
10
  # Permissions.
9
11
  POSTGRESQL_STORAGE_PERMISSIONS = 0o700
10
12
 
@@ -19,3 +21,10 @@ REWIND_USER = "rewind"
19
21
  SNAP_USER = "_daemon_"
20
22
  USER = "operator"
21
23
  SYSTEM_USERS = [MONITORING_USER, REPLICATION_USER, REWIND_USER, USER]
24
+
25
+
26
+ class Substrates(str, Enum):
27
+ """Possible substrates."""
28
+
29
+ K8S = "k8s"
30
+ VM = "vm"
@@ -30,7 +30,13 @@ import psycopg2
30
30
  from ops import ConfigData
31
31
  from psycopg2.sql import SQL, Identifier, Literal
32
32
 
33
- from ..config.literals import BACKUP_USER, POSTGRESQL_STORAGE_PERMISSIONS, SNAP_USER, SYSTEM_USERS
33
+ from ..config.literals import (
34
+ BACKUP_USER,
35
+ POSTGRESQL_STORAGE_PERMISSIONS,
36
+ SNAP_USER,
37
+ SYSTEM_USERS,
38
+ Substrates,
39
+ )
34
40
  from .filesystem import change_owner
35
41
 
36
42
  # Groups to distinguish HBA access
@@ -60,6 +66,7 @@ ALLOWED_ROLES = {
60
66
  }
61
67
 
62
68
  INVALID_DATABASE_NAME_BLOCKING_MESSAGE = "invalid database name"
69
+ INVALID_DATABASE_NAMES = ["databases", "postgres", "template0", "template1"]
63
70
  INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"
64
71
 
65
72
  REQUIRED_PLUGINS = {
@@ -216,6 +223,7 @@ class PostgreSQL:
216
223
 
217
224
  def __init__(
218
225
  self,
226
+ substrate: Substrates,
219
227
  primary_host: Optional[str],
220
228
  current_host: Optional[str],
221
229
  user: str,
@@ -223,6 +231,18 @@ class PostgreSQL:
223
231
  database: str,
224
232
  system_users: Optional[List[str]] = None,
225
233
  ):
234
+ """Create a PostgreSQL helper.
235
+
236
+ Args:
237
+ substrate: substrate where the charm is running (Substrates.K8S or Substrates.VM).
238
+ primary_host: hostname or address for primary database host.
239
+ current_host: hostname or address for the current database host.
240
+ user: username to connect as.
241
+ password: password for the user.
242
+ database: default database name.
243
+ system_users: list of system users.
244
+ """
245
+ self.substrate = substrate
226
246
  self.primary_host = primary_host
227
247
  self.current_host = current_host
228
248
  self.user = user
@@ -322,7 +342,7 @@ class PostgreSQL:
322
342
  if len(database) > 49:
323
343
  logger.error(f"Invalid database name (it must not exceed 49 characters): {database}.")
324
344
  raise PostgreSQLCreateDatabaseError(INVALID_DATABASE_NAME_BLOCKING_MESSAGE)
325
- if database in ["postgres", "template0", "template1"]:
345
+ if database in INVALID_DATABASE_NAMES:
326
346
  logger.error(f"Invalid database name: {database}.")
327
347
  raise PostgreSQLCreateDatabaseError(INVALID_DATABASE_NAME_BLOCKING_MESSAGE)
328
348
  plugins = plugins if plugins else []
@@ -1077,7 +1097,7 @@ class PostgreSQL:
1077
1097
  if temp_location is not None:
1078
1098
  # Fix permissions on the temporary tablespace location when a reboot happens and tmpfs is being used.
1079
1099
  temp_location_stats = os.stat(temp_location)
1080
- if (
1100
+ if self.substrate == Substrates.VM and (
1081
1101
  pwd.getpwuid(temp_location_stats.st_uid).pw_name != SNAP_USER
1082
1102
  or int(temp_location_stats.st_mode & 0o777) != POSTGRESQL_STORAGE_PERMISSIONS
1083
1103
  ):