Skip to content

Commit

Permalink
Merge branch 'ci_add_scc_mirror' into revert-9450-setup-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jordimassaguerpla authored Nov 21, 2024
2 parents e763a55 + 0194bae commit 6effbdc
Show file tree
Hide file tree
Showing 329 changed files with 8,164 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance_tests_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
required: true
type: string
env:
UYUNI_PROJECT: uyuni-project
UYUNI_PROJECT: jordimassaguerpla
UYUNI_VERSION: master
NO_AUTH_REGISTRY: no_auth_registry
CUCUMBER_PUBLISH_TOKEN: ${{ secrets.CUCUMBER_PUBLISH_TOKEN }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;

import spark.route.HttpMethod;

Expand Down Expand Up @@ -104,7 +108,7 @@ public class HttpClientAdapter {
public HttpClientAdapter() {
Optional<SSLConnectionSocketFactory> sslSocketFactory = Optional.empty();
try {
SSLContext sslContext = SSLContext.getDefault();
SSLContext sslContext = buildSslSocketContext();
List<String> supportedProtocols = Arrays.asList(sslContext.getSupportedSSLParameters().getProtocols());
List<String> wantedProtocols = Arrays.asList("TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3");
wantedProtocols.retainAll(supportedProtocols);
Expand Down Expand Up @@ -169,6 +173,38 @@ public HttpClientAdapter() {
httpClient = clientBuilder.build();
}

private SSLContext buildSslSocketContext() throws NoSuchAlgorithmException {

LOG.info("Started checking for certificates and if it finds the certificates will be loaded...");

String keyStoreLoc = System.getProperty("javax.net.ssl.trustStore",
System.getProperty("java.home") + "/lib/security/cacerts");
SSLContext context;

try (InputStream in = new FileInputStream(keyStoreLoc)) {
// Create a KeyStore containing our trusted CAs
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(in, null);

// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keystore);

// Create an SSLContext that uses our TrustManager
context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
LOG.info("Completed loading of certificates.");
}
catch (Exception e) {
LOG.error("unable to create ssl context {}." +
"If the trust store has been updated, some certificates might not have been loaded.",
e.getMessage());
context = SSLContext.getDefault();
}
return context;
}

/**
* Custom ProxyRoutePlanner that routes the request to a proxy
* or to a direct route depending on the setting
Expand Down
129 changes: 124 additions & 5 deletions java/code/src/com/redhat/rhn/frontend/xmlrpc/system/SystemHandler.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 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 @@ -2859,7 +2860,7 @@ public int provisionVirtualGuest(User loggedInUser, Integer sid, String guestNam
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2883,7 +2884,7 @@ public int provisionSystem(User loggedInUser, Integer sid, String profileName)
* @param request the spark request
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2900,14 +2901,66 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
return provisionSystem(loggedInUser, request, sid, profileName, new Date());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid, Integer proxy, String profileName)
throws FaultException {
return provisionSystem(loggedInUser, RhnXmlRpcServer.getRequest(), sid, proxy, profileName, new Date());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile.
*
* @param loggedInUser The current user
* @param request the spark request
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid, Integer proxy,
String profileName)
throws FaultException {
return provisionSystem(loggedInUser, request, sid, proxy, profileName, new Date());
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2934,7 +2987,7 @@ public int provisionSystem(User loggedInUser, Integer sid,
* @param sid of the system to be provisioned
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns 1 if successful, exception otherwise
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
Expand All @@ -2950,6 +3003,63 @@ public int provisionSystem(User loggedInUser, Integer sid,
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
String profileName, Date earliestDate)
throws FaultException {
return provisionSystem(loggedInUser, request , sid, null, profileName, earliestDate);
}

/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.param #param("$date", "earliestDate")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.HTTP)
public int provisionSystem(User loggedInUser, Integer sid,
Integer proxy, String profileName, Date earliestDate)
throws FaultException {
HttpServletRequest request = RhnXmlRpcServer.getRequest();
return provisionSystem(loggedInUser, request, sid, proxy, profileName, earliestDate);
}
/**
* Provision a system using the specified kickstart/autoinstallation profile at specified time.
*
* @param loggedInUser The current user
* @param request the request
* @param sid of the system to be provisioned
* @param proxy ID of the proxy to use
* @param profileName of Profile to be used.
* @param earliestDate when the autoinstallation needs to be scheduled
* @return Returns id of the action if successful, exception otherwise
* @throws FaultException A FaultException is thrown if the server corresponding to
* id cannot be found or profile is not found.
*
* @apidoc.doc Provision a system using the specified kickstart/autoinstallation profile.
* @apidoc.param #session_key()
* @apidoc.param #param_desc("int", "sid", "ID of the system to be provisioned.")
* @apidoc.param #param_desc("int", "proxy", "ID of the proxy to use.")
* @apidoc.param #param_desc("string", "profileName", "Profile to use.")
* @apidoc.param #param("$date", "earliestDate")
* @apidoc.returntype #param_desc("int", "id", "ID of the action scheduled, otherwise exception thrown
* on error")
*/
@ApiIgnore(ApiType.XMLRPC)
public int provisionSystem(User loggedInUser, HttpServletRequest request, Integer sid,
Integer proxy, String profileName, Date earliestDate)
throws FaultException {
log.debug("provisionSystem called.");

// Lookup the server so we can validate it exists and throw error if not.
Expand All @@ -2970,10 +3080,19 @@ public int provisionSystem(User loggedInUser, HttpServletRequest request, Intege
KickstartHelper helper = new KickstartHelper(request);
String host = helper.getKickstartHost();


KickstartScheduleCommand cmd = new KickstartScheduleCommand(
Long.valueOf(sid),
ksdata.getId(), loggedInUser, earliestDate, host);
if (proxy != null) {
Server proxyServer = SystemManager.lookupByIdAndOrg(Long.valueOf(proxy), loggedInUser.getOrg());
if (proxyServer == null) {
throw new FaultException(-2, "provisionError", "Requested proxy is not available");
}
if (!proxyServer.isProxy()) {
throw new FaultException(-2, "provisionError", "Requested proxy is not registered proxy");
}
cmd.setProxy(proxyServer);
}
ValidatorError ve = cmd.store();
if (ve != null) {
throw new FaultException(-2, "provisionError",
Expand Down
Loading

0 comments on commit 6effbdc

Please sign in to comment.