Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified Proxy Onboarding #9703

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 SUSE LLC
* Copyright (c) 2024-2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
Expand Down Expand Up @@ -32,6 +32,24 @@ private ErrorReportingStrategies() {
}

private static final Map<Object, Logger> OBJ_LOGGER = Collections.synchronizedMap(new WeakHashMap<>());
private static final RhnReportStrategy<RhnCustomError> VALIDATION_REPORT_STRATEGY;

static {
VALIDATION_REPORT_STRATEGY = errors -> {
if (!errors.isEmpty()) {
throw new RhnGeneralException(errors);
}
};
}


/**
* Returns a default validation reporting strategy
* @return RhnReportStrategy
*/
public static RhnReportStrategy<RhnCustomError> validationReportingStrategy() {
return VALIDATION_REPORT_STRATEGY;
}

/**
* Raise and log an exception
Expand Down
28 changes: 28 additions & 0 deletions java/code/src/com/redhat/rhn/common/RhnCustomError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/

package com.redhat.rhn.common;

public class RhnCustomError {
private final String message;

public RhnCustomError(String messageIn) {
this.message = messageIn;
}

public String getMessage() {
return message;
}
}
66 changes: 66 additions & 0 deletions java/code/src/com/redhat/rhn/common/RhnErrorReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/

package com.redhat.rhn.common;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RhnErrorReport {
private final List<RhnCustomError> errors = Collections.synchronizedList(new ArrayList<>());

/**
* Registers a new error in the error report.
*
* @param message The error message.
*/
public void register(String message) {
errors.add(new RhnCustomError(message));
}

/**
* Checks if any errors have been registered.
*
* @return true if there are errors; false otherwise.
*/
public boolean hasErrors() {
return !errors.isEmpty();
}

/**
* Returns a copy of the current list of errors.
*
* @return A copy of the errors list.
*/
public List<RhnCustomError> getErrors() {
return new ArrayList<>(errors);
}

/**
* Logs the errors following a RhnReportStrategy.
* @param strategy The reporting strategy.
*/
public void report(RhnReportStrategy<RhnCustomError> strategy) {
strategy.report(errors);
}

/**
* Logs the errors using the default validation reporting strategy.
*/
public void report() {
ErrorReportingStrategies.validationReportingStrategy().report(errors);
}
}
34 changes: 34 additions & 0 deletions java/code/src/com/redhat/rhn/common/RhnGeneralException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/

package com.redhat.rhn.common;

import java.util.List;

public class RhnGeneralException extends RuntimeException {
private List<RhnCustomError> errors;

/**
* Constructor
* @param errorsIn the list of errors
*/
public RhnGeneralException(List<RhnCustomError> errorsIn) {
this.errors = errorsIn;
}

public List<RhnCustomError> getErrors() {
return errors;
}
}
27 changes: 27 additions & 0 deletions java/code/src/com/redhat/rhn/common/RhnReportStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2025 SUSE LLC
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.redhat.rhn.common;

import java.util.List;

public interface RhnReportStrategy<E> {

/**
* Report a list of errors
* @param errors the list of errors
*/
void report(List<E> errors);

}
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ SELECT 1
WHEN 'monitoring_entitled' then 'Monitoring'
WHEN 'ansible_control_node' then 'Ansible Control Node'
WHEN 'peripheral_server' then 'Peripheral Server'
WHEN 'proxy_entitled' then 'Proxy'
END)
</query>
</write-mode>
Expand Down
26 changes: 26 additions & 0 deletions java/code/src/com/redhat/rhn/common/security/acl/Access.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2015--2025 SUSE LLC
* Copyright (c) 2009--2015 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
Expand Down Expand Up @@ -676,4 +677,29 @@ public boolean aclSystemHasModularChannels(Map<String, Object> ctx, String[] par

return server.getChannels().stream().anyMatch(Channel::isModular);
}

/**
* Uses the sid param to decide if a system is a proxy
* @param ctx Context Map to pass in
* @param params Parameters to use (unused)
* @return true if a system is a proxy, false otherwise
*/
public boolean aclSystemIsConvertibleToProxy(Map<String, Object> ctx, String[] params) {
Long sid = getAsLong(ctx.get("sid"));
User user = (User) ctx.get("user");
Server lookedUp = SystemManager.lookupByIdAndUser(sid, user);

return lookedUp.isConvertibleToProxy();
}

/**
* Checks is server has a proxy entitlement
*
* @param ctx Context map to pass in.
* @param params Parameters to use to fetch from context.
* @return True if system has proxy entitlement, false otherwise.
*/
public boolean aclSystemHasProxyEntitlement(Map<String, Object> ctx, String[] params) {
return SystemManager.serverHasProxyEntitlement(getAsLong(ctx.get("sid")));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2017--2025 SUSE LLC
* Copyright (c) 2009--2017 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
Expand Down Expand Up @@ -1234,8 +1235,15 @@ public static void delete(ServerAction serverAction) {
lookupActionTypeByLabel("coco.attestation");

/**
* The constant representing appstreams changes action.
* The constant representing appstreams changes action. [ID:524]
*/
public static final ActionType TYPE_APPSTREAM_CONFIGURE = lookupActionTypeByLabel("appstreams.configure");


/**
* The constant representing "Apply Proxy Configuration" [ID:525]
*/
public static final ActionType TYPE_PROXY_CONFIGURATION_APPLY =
lookupActionTypeByLabel("proxy_configuration.apply");
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2025 SUSE LLC
* Copyright (c) 2009--2010 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public License,
* version 2 (GPLv2). There is NO WARRANTY for this software, express or
* implied, including the implied warranties of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
* along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* Red Hat trademarks are not licensed under GPLv2. No permission is
* granted to use or replicate Red Hat trademarks that are incorporated
* in this software or its documentation.
*/
package com.redhat.rhn.domain.action;


import com.redhat.rhn.domain.server.MinionSummary;
import com.redhat.rhn.domain.server.Pillar;

import com.suse.manager.webui.services.SaltServerActionService;
import com.suse.proxy.ProxyConfigUtils;
import com.suse.salt.netapi.calls.LocalCall;
import com.suse.salt.netapi.calls.modules.State;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* ProxyConfigurationApply - Class representing TYPE_PROXY_CONFIGURATION_APPLY action
*/
public class ProxyConfigurationApplyAction extends Action {

private final Pillar pillar;
private final Map<String, Object> proxyConfigFiles;

/**
* Default constructor
* @param pillarIn the pillar
* @param proxyConfigFilesIn the proxy configuration files
*/
public ProxyConfigurationApplyAction(Pillar pillarIn, Map<String, Object> proxyConfigFilesIn) {
this.setActionType(ActionFactory.TYPE_PROXY_CONFIGURATION_APPLY);
this.pillar = pillarIn;
this.proxyConfigFiles = proxyConfigFilesIn;
}

public Pillar getPillar() {
return pillar;
}

public Map<String, Object> getProxyConfigFiles() {
return proxyConfigFiles;
}

/**
* Get the apply_proxy_config local call
* @param minions the minions
* @return the apply_proxy_config local call
*/
public Map<LocalCall<?>, List<MinionSummary>> getApplyProxyConfigAction(List<MinionSummary> minions) {
Map<String, Object> data = new HashMap<>();
data.putAll(ProxyConfigUtils.applyProxyConfigDataFromPillar(getPillar()));
data.putAll(getProxyConfigFiles());

return Map.of(
State.apply(Collections.singletonList(SaltServerActionService.APPLY_PROXY_CONFIG), Optional.of(data)),
minions
);
}
}
Loading
Loading