3030from  requests  import  ConnectionError 
3131from  tenacity  import  RetryError 
3232
33- from  constants  import  PEER 
33+ from  constants  import  PEER ,  USER 
3434from  patroni  import  NotReadyError , Patroni 
3535from  relations .db  import  DbProvides 
3636from  relations .postgresql_provider  import  PostgreSQLProvider 
@@ -59,7 +59,7 @@ def __init__(self, *args):
5959        self .framework .observe (self .on .postgresql_pebble_ready , self ._on_postgresql_pebble_ready )
6060        self .framework .observe (self .on .upgrade_charm , self ._on_upgrade_charm )
6161        self .framework .observe (
62-             self .on .get_postgres_password_action , self ._on_get_postgres_password 
62+             self .on .get_operator_password_action , self ._on_get_operator_password 
6363        )
6464        self .framework .observe (self .on .get_primary_action , self ._on_get_primary )
6565        self .framework .observe (self .on .update_status , self ._on_update_status )
@@ -74,8 +74,8 @@ def postgresql(self) -> PostgreSQL:
7474        """Returns an instance of the object used to interact with the database.""" 
7575        return  PostgreSQL (
7676            host = self .primary_endpoint ,
77-             user = "postgres" ,
78-             password = self ._get_postgres_password (),
77+             user = USER ,
78+             password = self ._get_operator_password (),
7979            database = "postgres" ,
8080        )
8181
@@ -250,11 +250,11 @@ def _get_hostname_from_unit(self, member: str) -> str:
250250    def  _on_leader_elected (self , event : LeaderElectedEvent ) ->  None :
251251        """Handle the leader-elected event.""" 
252252        data  =  self ._peers .data [self .app ]
253-         postgres_password  =  data .get ("postgres -password" , None )
253+         operator_password  =  data .get ("operator -password" , None )
254254        replication_password  =  data .get ("replication-password" , None )
255255
256-         if  postgres_password  is  None :
257-             self ._peers .data [self .app ]["postgres -password" ] =  new_password ()
256+         if  operator_password  is  None :
257+             self ._peers .data [self .app ]["operator -password" ] =  new_password ()
258258
259259        if  replication_password  is  None :
260260            self ._peers .data [self .app ]["replication-password" ] =  new_password ()
@@ -387,9 +387,9 @@ def _create_resources(self) -> None:
387387                self .unit .status  =  BlockedStatus (f"failed to create services { e }  )
388388                return 
389389
390-     def  _on_get_postgres_password (self , event : ActionEvent ) ->  None :
391-         """Returns the password for the postgres  user as an action response.""" 
392-         event .set_results ({"postgres -password" : self ._get_postgres_password ()})
390+     def  _on_get_operator_password (self , event : ActionEvent ) ->  None :
391+         """Returns the password for the operator  user as an action response.""" 
392+         event .set_results ({"operator -password" : self ._get_operator_password ()})
393393
394394    def  _on_get_primary (self , event : ActionEvent ) ->  None :
395395        """Get primary instance.""" 
@@ -501,8 +501,8 @@ def _postgresql_layer(self) -> Layer:
501501                        "PATRONI_SCOPE" : f"patroni-{ self ._name }  ,
502502                        "PATRONI_REPLICATION_USERNAME" : "replication" ,
503503                        "PATRONI_REPLICATION_PASSWORD" : self ._replication_password ,
504-                         "PATRONI_SUPERUSER_USERNAME" : "postgres" ,
505-                         "PATRONI_SUPERUSER_PASSWORD" : self ._get_postgres_password (),
504+                         "PATRONI_SUPERUSER_USERNAME" : USER ,
505+                         "PATRONI_SUPERUSER_PASSWORD" : self ._get_operator_password (),
506506                    },
507507                }
508508            },
@@ -519,10 +519,10 @@ def _peers(self) -> Relation:
519519        """ 
520520        return  self .model .get_relation (PEER )
521521
522-     def  _get_postgres_password (self ) ->  str :
523-         """Get postgres  user password.""" 
522+     def  _get_operator_password (self ) ->  str :
523+         """Get operator  user password.""" 
524524        data  =  self ._peers .data [self .app ]
525-         return  data .get ("postgres -password" , None )
525+         return  data .get ("operator -password" , None )
526526
527527    @property  
528528    def  _replication_password (self ) ->  str :
0 commit comments