Skip to content

Commit 75c8fb8

Browse files
committed
issue #367 root, perms
1 parent e18f813 commit 75c8fb8

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

apiserver/perms.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func InitializePerms() {
9999
PermMap[RESTORE_PERM] = "yes"
100100
PermMap[CREATE_PGPOOL_PERM] = "yes"
101101
PermMap[DELETE_PGPOOL_PERM] = "yes"
102-
log.Infof("loading PermMap with %d Permissions\n", len(PermMap))
102+
log.Infof("loading PermMap with %d Permissions", len(PermMap))
103103

104104
readRoles()
105105
}
@@ -136,8 +136,8 @@ func readRoles() {
136136
} else {
137137
fields := strings.Split(strings.TrimSpace(line), ":")
138138
if len(fields) != 2 {
139-
log.Infoln("rolename:perm format not followed")
140-
log.Error(errors.New("invalid format found in pgorole, role:perm format must be followed"))
139+
log.Infoln("rolename:permission format not followed")
140+
log.Error(errors.New("invalid format found in pgorole - rolename:permission format must be followed"))
141141
log.Errorf("bad line is %s\n", fields)
142142
os.Exit(2)
143143
} else {
@@ -148,13 +148,13 @@ func readRoles() {
148148
for _, v := range perms {
149149
cleanPerm := strings.TrimSpace(v)
150150
if PermMap[cleanPerm] == "" {
151-
log.Errorf(" [%s] not a valid permission for role [%s]\n", cleanPerm, roleName)
151+
log.Errorf(" [%s] not a valid permission for role [%s]", cleanPerm, roleName)
152152
os.Exit(2)
153153
}
154154
permMap[cleanPerm] = "yes"
155155
}
156156
RoleMap[roleName] = permMap
157-
log.Infof("loaded Role [%s] Perms Ct [%d] Perms [%v]\n", roleName, len(permMap), permMap)
157+
log.Infof("loaded Role [%s] Perms Ct [%d] Perms [%v]", roleName, len(permMap), permMap)
158158
}
159159
}
160160
}

apiserver/root.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func Initialize() {
9292

9393
Namespace = os.Getenv("NAMESPACE")
9494
if Namespace == "" {
95-
log.Error("NAMESPACE env var is required")
95+
log.Error("NAMESPACE environment variable is required")
9696
os.Exit(2)
9797
}
9898
log.Info("Namespace is [" + Namespace + "]")
@@ -180,7 +180,7 @@ func initConfig() {
180180
os.Exit(2)
181181
}
182182
}
183-
log.Infof("BasicAuth is %v\n", BasicAuth)
183+
log.Infof("BasicAuth is %v", BasicAuth)
184184

185185
if !validStorageSettings() {
186186
log.Error("Storage Settings are not defined correctly, can't continue")
@@ -245,7 +245,7 @@ func validateCredentials() error {
245245
var err error
246246

247247
for _, v := range Credentials {
248-
log.Infof("validating user %s and role %s ", v.Username, v.Role)
248+
log.Infof("validating user %s and role %s", v.Username, v.Role)
249249
if RoleMap[v.Role] == nil {
250250
errMsg := fmt.Sprintf("role not found on pgouser user [%s], invalid role was [%s]", v.Username, v.Role)
251251
log.Error(errMsg)
@@ -280,11 +280,11 @@ func BasicAuthzCheck(username, perm string) bool {
280280
if creds == (CredentialDetail{}) {
281281
//this means username not found in pgouser file
282282
//should not happen at this point in code!
283-
log.Error("%s not found in pgouser file\n", username)
283+
log.Error("%s not found in pgouser file", username)
284284
return false
285285
}
286286

287-
log.Infof(" BasicAuthzCheck %s %s %v\n", creds.Role, perm, HasPerm(creds.Role, perm))
287+
log.Infof("BasicAuthzCheck %s %s %v", creds.Role, perm, HasPerm(creds.Role, perm))
288288
return HasPerm(creds.Role, perm)
289289

290290
}
@@ -295,34 +295,34 @@ func Authn(perm string, w http.ResponseWriter, r *http.Request) error {
295295

296296
username, password, authOK := r.BasicAuth()
297297
if AuditFlag {
298-
log.Infof("[audit] %s username=[%s] method=[%s] ip=[%s]\n", perm, username, r.Method, r.RemoteAddr)
298+
log.Infof("[audit] %s username=[%s] method=[%s] ip=[%s]", perm, username, r.Method, r.RemoteAddr)
299299
}
300300

301-
log.Debugf("Authn Attempt %s username=[%s]\n", perm, username)
301+
log.Debugf("Authentication Attempt %s username=[%s]", perm, username)
302302
if authOK == false {
303303
http.Error(w, "Not authorized", 401)
304304
return errors.New("Not Authorized")
305305
}
306306

307307
if !BasicAuthCheck(username, password) {
308-
log.Errorf("Authn Failed %s username=[%s]\n", perm, username)
308+
log.Errorf("Authentication Failed %s username=[%s]", perm, username)
309309
http.Error(w, "Not authenticated in apiserver", 401)
310310
return errors.New("Not Authenticated")
311311
}
312312

313313
if !BasicAuthzCheck(username, perm) {
314-
log.Errorf("Authn Failed %s username=[%s]\n", perm, username)
314+
log.Errorf("Authentication Failed %s username=[%s]", perm, username)
315315
http.Error(w, "Not authorized for this apiserver action", 401)
316-
return errors.New("Not Authorized for this apiserver action")
316+
return errors.New("Not authorized for this apiserver action")
317317
}
318318

319-
log.Debug("Authn Success")
319+
log.Debug("Authentication Success")
320320
return err
321321

322322
}
323323

324324
func validContainerResourcesSettings() bool {
325-
log.Infof("ContainerResources has %d definitions \n", len(Pgo.ContainerResources))
325+
log.Infof("ContainerResources has %d definitions", len(Pgo.ContainerResources))
326326

327327
//validate any Container Resources in pgo.yaml for correct formats
328328
if !IsValidContainerResourceValues() {
@@ -348,7 +348,7 @@ func validContainerResourcesSettings() bool {
348348
}
349349

350350
func validStorageSettings() bool {
351-
log.Infof("Storage has %d definitions\n", len(Pgo.Storage))
351+
log.Infof("Storage has %d definitions", len(Pgo.Storage))
352352

353353
ps := Pgo.PrimaryStorage
354354
if IsValidStorageName(ps) {
@@ -420,26 +420,26 @@ func IsValidContainerResourceValues() bool {
420420
var err error
421421

422422
for k, v := range Pgo.ContainerResources {
423-
log.Infof("Container Resources %s [%v]\n", k, v)
423+
log.Infof("Container Resources %s [%v]", k, v)
424424
resources, _ := Pgo.GetContainerResource(k)
425425
_, err = resource.ParseQuantity(resources.RequestsMemory)
426426
if err != nil {
427-
log.Errorf("%s.RequestsMemory value invalid format\n", k)
427+
log.Errorf("%s.RequestsMemory value invalid format", k)
428428
return false
429429
}
430430
_, err = resource.ParseQuantity(resources.RequestsCPU)
431431
if err != nil {
432-
log.Errorf("%s.RequestsCPU value invalid format\n", k)
432+
log.Errorf("%s.RequestsCPU value invalid format", k)
433433
return false
434434
}
435435
_, err = resource.ParseQuantity(resources.LimitsMemory)
436436
if err != nil {
437-
log.Errorf("%s.LimitsMemory value invalid format\n", k)
437+
log.Errorf("%s.LimitsMemory value invalid format", k)
438438
return false
439439
}
440440
_, err = resource.ParseQuantity(resources.LimitsCPU)
441441
if err != nil {
442-
log.Errorf("%s.LimitsCPU value invalid format\n", k)
442+
log.Errorf("%s.LimitsCPU value invalid format", k)
443443
return false
444444
}
445445
}

0 commit comments

Comments
 (0)