Skip to content

Commit

Permalink
fixup! manager api for report db configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Jan 28, 2025
1 parent 9db0200 commit 87e5f8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
25 changes: 12 additions & 13 deletions java/code/src/com/redhat/rhn/taskomatic/task/ReportDBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.logging.log4j.Logger;
import org.hibernate.Session;

import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -221,13 +220,13 @@ public boolean hasDBUser(Session session, String username) {
* @param password the new password
*/
public void createDBUser(Session session, String dbName, String username, String password) {
final String sql = MessageFormat.format("""
CREATE ROLE {0} WITH LOGIN PASSWORD ''{1}'' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
GRANT CONNECT ON DATABASE {2} TO {0};
GRANT USAGE ON SCHEMA public TO {0};
GRANT SELECT ON ALL TABLES IN SCHEMA public TO {0};
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO {0};
""", username, password, dbName);
final String sql = """
CREATE ROLE %1$s WITH LOGIN PASSWORD ''%2$s'' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
GRANT CONNECT ON DATABASE %3$s TO %1$s;
GRANT USAGE ON SCHEMA public TO %1$s;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO %1$s;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO %1$s;
""".formatted(username, password, dbName);
var i = new GeneratedWriteMode("grant.permissions", session, sql, Collections.emptyList());
i.executeUpdate(Collections.emptyMap());
}
Expand All @@ -239,7 +238,7 @@ public void createDBUser(Session session, String dbName, String username, String
* @param password the new password to set
*/
public void changeDBPassword(Session session, String username, String password) {
final String sql = MessageFormat.format("ALTER USER {0} PASSWORD ''{1}''", username, password);
final String sql = "ALTER USER %1$s PASSWORD ''%2$s''".formatted(username, password);
var i = new GeneratedWriteMode("alter.user", session, sql, Collections.emptyList());
i.executeUpdate(Collections.emptyMap());
}
Expand All @@ -257,10 +256,10 @@ public void dropDBUser(Session session, String username) {
throw new IllegalArgumentException("Forbidden to drop restricted user: " + username);
}

final String sql = MessageFormat.format("""
DROP OWNED BY {0};
DROP ROLE {0};
""", username);
final String sql = """
DROP OWNED BY %1$s;
DROP ROLE %1$s;
""".formatted(username);

var i = new GeneratedWriteMode("drop.user", session, sql, Collections.emptyList());
i.executeUpdate(Collections.emptyMap());
Expand Down
4 changes: 1 addition & 3 deletions java/code/src/com/suse/manager/hub/HubManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import java.security.cert.CertificateException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -301,8 +300,7 @@ public void setReportDbUser(User user, Server server, boolean forcePwChange)
mgrServerInfo.setReportDbCredentials(credentials);

Optional<IssPeripheral> issPeripheral = server.getFqdns().stream()
.map(fqdn -> hubFactory.lookupIssPeripheralByFqdn(fqdn.getName()).orElse(null))
.filter(Objects::nonNull)
.flatMap(fqdn -> hubFactory.lookupIssPeripheralByFqdn(fqdn.getName()).stream())
.findFirst();
if (issPeripheral.isPresent()) {
IssPeripheral remoteServer = issPeripheral.get();
Expand Down

0 comments on commit 87e5f8b

Please sign in to comment.