MCPcopy
hub / github.com/acepanel/panel / SetPostgresPassword

Method SetPostgresPassword

internal/apps/postgresql/app.go:204–236  ·  view source on GitHub ↗

SetPostgresPassword 设置 postgres 用户密码

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

202
203// SetPostgresPassword 设置 postgres 用户密码
204func (s *App) SetPostgresPassword(w http.ResponseWriter, r *http.Request) {
205 req, err := service.Bind[SetPostgresPassword](r)
206 if err != nil {
207 service.Error(w, http.StatusUnprocessableEntity, "%v", err)
208 return
209 }
210
211 oldPassword, _ := s.settingRepo.Get(biz.SettingKeyPostgresPassword)
212 port := s.getPort()
213 postgres, err := db.NewPostgres("postgres", oldPassword, "127.0.0.1", port)
214 if err != nil {
215 // 直接修改密码
216 if _, err = shell.Execf(`su - postgres -c "psql -p %d -c \"ALTER USER postgres WITH PASSWORD '%s';\""`, port, req.Password); err != nil {
217 service.Error(w, http.StatusInternalServerError, s.t.Get("failed to set postgres password: %v", err))
218 return
219 }
220 } else {
221 defer postgres.Close()
222 if err = postgres.UserPassword("postgres", req.Password); err != nil {
223 service.Error(w, http.StatusInternalServerError, s.t.Get("failed to set postgres password: %v", err))
224 return
225 }
226 }
227
228 if err = s.settingRepo.Set(biz.SettingKeyPostgresPassword, req.Password); err != nil {
229 service.Error(w, http.StatusInternalServerError, s.t.Get("failed to set postgres password: %v", err))
230 return
231 }
232
233 _ = s.databaseServerRepo.UpdatePassword("local_postgresql", req.Password)
234
235 service.Success(w, nil)
236}
237
238// GetConfigTune 获取 PostgreSQL 配置调整参数
239func (s *App) GetConfigTune(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Implementers 15

Appinternal/apps/postgresql/app.go
Appinternal/apps/mongodb/app.go
Appinternal/apps/prometheus/app.go
Appinternal/apps/codeserver/app.go
Appinternal/apps/mariadb/app.go
Appinternal/apps/openresty/app.go
Appinternal/apps/supervisor/app.go
Appinternal/apps/minio/app.go
Appinternal/apps/s3fs/app.go
Appinternal/apps/mysql/app.go
Appinternal/apps/gitea/app.go
Appinternal/apps/opensearch/app.go

Calls 10

getPortMethod · 0.95
CloseMethod · 0.95
UserPasswordMethod · 0.95
ErrorFunction · 0.92
NewPostgresFunction · 0.92
ExecfFunction · 0.92
SuccessFunction · 0.92
GetMethod · 0.65
SetMethod · 0.65
UpdatePasswordMethod · 0.65

Tested by

no test coverage detected