Skip to content

Commit

Permalink
Merge pull request #77 from at88mph/private-harbor-rework
Browse files Browse the repository at this point in the history
feat: rename registryxxx to repositoryxxx to separate from ivoa regis…
  • Loading branch information
at88mph authored Nov 15, 2024
2 parents 2d0bbe7 + ed1d6a8 commit 1b762f5
Show file tree
Hide file tree
Showing 11 changed files with 409 additions and 249 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# tags with and without build number so operators use the versioned
# tag but we always keep a timestamped tag in case a semantic tag gets
# replaced accidentally
VER=0.3.0
VER=0.3.1
TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")"
unset VER
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ plugins {

// IntelliJ IDEA plugin here to allow integration tests to appear properly in IDEs.
id 'idea'

id 'com.diffplug.spotless' version '6.25.0'
id 'jacoco'
}

node {
version = '18.18.0'
version = '22.11.0'
}

repositories {
mavenLocal()
mavenCentral()
}


dependencies {
implementation 'com.opencsv:opencsv:[5.1,6.0)'
implementation 'commons-net:commons-net:3.9.0'
Expand Down Expand Up @@ -53,7 +55,8 @@ war {
archiveName 'science-portal.war'
}

task buildReactApp(type: NodeTask, dependsOn: 'npmInstall') {
tasks.register('buildReactApp', NodeTask) {
dependsOn 'npmInstall'
script = project.file('node_modules/webpack/bin/webpack.js')
args = [
'--mode', 'development',
Expand Down
25 changes: 17 additions & 8 deletions public/dev/js/science_portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,21 @@
event.preventDefault()
portalCore.clearAjaxAlert(portalCore.pageSections.form)

const _prunedFormData = new FormData();
const _prunedFormData = new FormData()
const form = event.target

for (let i= 0; i < event.target.length; i++) {
const currentValue = event.target[i];
for (const currentValue of form) {
_prunedFormData.append(currentValue.name, currentValue.value)
console.log(currentValue.name + ": " + currentValue.value)
}

// This is sent from the Private (Advanced) form
const repositoryHostFieldName = "repositoryHost"
if (_prunedFormData.has(repositoryHostFieldName)) {
const repositoryHost = _prunedFormData.get(repositoryHostFieldName)
const image = `${repositoryHost}/${_prunedFormData.get("image")}`

_prunedFormData.delete(repositoryHostFieldName)
_prunedFormData.set("image", image)
}

portalCore.setPageState(portalCore.pageSections.form, "primary", true, '')
Expand Down Expand Up @@ -454,12 +463,12 @@
request.open("POST", serviceURL)

// Request headers can only be set after the request is open.
const secretFieldName = "registryAuthSecret"
const secretHeader = "x-registry-secret"
const usernameHeader = "x-registry-username"
const secretFieldName = "repositoryAuthSecret"
const secretHeader = "x-repository-secret"
const usernameHeader = "x-repository-username"
if (sessionData.has(secretFieldName)) {
const secret = sessionData.get(secretFieldName)
const username = sessionData.get("registryAuthUsername")
const username = sessionData.get("repositoryAuthUsername")
if (secret) {
request.setRequestHeader(secretHeader, secret)
}
Expand Down
4 changes: 3 additions & 1 deletion public/dev/js/science_portal_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
userInfoEndpoint: '/science-portal/userinfo',
sessionEndpoint: '/science-portal/session',
imageEndpoint: '/science-portal/image',
contextEndpoint: '/science-portal/context'
contextEndpoint: '/science-portal/context',
repositoryEndpoint: '/science-portal/repository',
}
}
}
Expand Down Expand Up @@ -287,6 +288,7 @@
"base": baseURL,
"session": `${baseURL}${cadc.web.science.portal.core.sessionEndpoint}`,
"context": `${baseURL}${cadc.web.science.portal.core.contextEndpoint}`,
"repositoryHosts": `${baseURL}${cadc.web.science.portal.core.repositoryEndpoint}`,
"images": `${baseURL}${cadc.web.science.portal.core.imageEndpoint}`
}

Expand Down
55 changes: 37 additions & 18 deletions public/dev/js/science_portal_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
onLoadFormDataError: new jQuery.Event('sciPort:onLoadFormDataError'),
onLoadImageDataDone: new jQuery.Event('sciPort:onLoadImageDataDone'),
onLoadImageDataError: new jQuery.Event('sciPort:onLoadImageDataError'),
onLoadRepositoryHostsDone: new jQuery.Event('sciPort:onLoadRepositoryHostsDone'),
onLoadRepositoryHostsError: new jQuery.Event('sciPort:onLoadRepositoryHostsError'),
onLoadContextDataDone: new jQuery.Event('sciPort:onLoadContextDataDone'),
onLoadContextDataError: new jQuery.Event('sciPort:onLoadContextDataError'),
}
Expand All @@ -36,10 +38,11 @@
this._imageData = []
this._contextData = {}
this._sessionTypeList = null
this._repositoryHosts = []
this._sessionTypeMap = {}

// Used to determine when all the data is collected from the form
// 1 - call for context informtaion
// 1 - call for context information
// 2 - n: for calls to get image lists for each type
this._ajaxCallCount = 0

Expand Down Expand Up @@ -74,13 +77,16 @@

// Set up counter for ajax calls used to load page data
// context + image list
_selfPortalForm._ajaxCallCount = 2;
_selfPortalForm._ajaxCallCount = 3;

// Start loading context data
_selfPortalForm.getContextData()

// Start loading container image lists
_selfPortalForm.getFullImageList()

// Obtain the configured repository hosts
_selfPortalForm.getRepositoryHosts()
}


Expand Down Expand Up @@ -191,28 +197,40 @@
}
}

function getRepositoryHosts() {
const fullListURL = _selfPortalForm.sessionURLs.repositoryHosts;
Promise.resolve(_getAjaxData(fullListURL))
.then(function (repositoryHostArray) {
_selfPortalForm._repositoryHosts = _selfPortalForm._repositoryHosts.concat(repositoryHostArray)
_selfPortalForm._ajaxCallCount--
if (_selfPortalForm._ajaxCallCount === 0) {
trigger(_selfPortalForm, cadc.web.science.portal.form.events.onLoadFormDataDone)
}
})
.catch(function (message) {
trigger(_selfPortalForm, cadc.web.science.portal.form.events.onLoadRepositoryHostsError, message)
})
}

function getFormDataForType(sessionType, sessionName) {
var _formData = {}
_formData.contextData = _selfPortalForm._contextData
_formData.imageList= _selfPortalForm.getImageListForType(sessionType)
_formData.types = _selfPortalForm._sessionTypeList
_formData.selectedType = sessionType
_formData.sessionName = sessionName
const _formData = {
contextData: _selfPortalForm._contextData,
imageList: _selfPortalForm.getImageListForType(sessionType),
repositoryHosts: _selfPortalForm._repositoryHosts,
types: _selfPortalForm._sessionTypeList,
selectedType: sessionType,
sessionName: sessionName
}

var tmpMapEntry = _selfPortalForm.getMapEntry(sessionType)
const tmpMapEntry = _selfPortalForm.getMapEntry(sessionType)

// Translate list of allowed fields into booleans for variable fields
// ie: showRAM and showCores

var showcores = false
if (tmpMapEntry.form_fields.includes("cores")) {
showcores = true
}
var showram = false
if (tmpMapEntry.form_fields.includes("memory")) {
showram = true
}
_formData.formFields = {"showCores": showcores, "showRAM": showram}
const showCores = tmpMapEntry.form_fields.includes("cores")
const showRAM = tmpMapEntry.form_fields.includes("memory")

_formData.formFields = {"showCores": showCores, "showRAM": showRAM}

return _formData
}
Expand Down Expand Up @@ -338,6 +356,7 @@
getCoresArray: getCoresArray,
getCoresDefault: getCoresDefault,
getFullImageList: getFullImageList,
getRepositoryHosts: getRepositoryHosts,
getImageListForType: getImageListForType,
getSessionTypeDefault: getSessionTypeDefault,
getSessionTypeList: getSessionTypeList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,36 @@
import ca.nrc.cadc.reg.client.LocalAuthority;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.util.StringUtil;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;

import java.util.NoSuchElementException;
import java.util.Set;
import org.apache.commons.configuration2.CombinedConfiguration;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.SystemConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.tree.MergeCombiner;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.opencadc.token.Client;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Arrays;
import java.util.Date;
import java.util.NoSuchElementException;
import java.util.Set;


public class ApplicationConfiguration {

// Included in the JSP
public static final long BUILD_TIME_MS = new Date().getTime();

public static final String FIRST_PARTY_COOKIE_NAME = "__Host-science-portal-auth";

private static final Logger LOGGER = Logger.getLogger(ApplicationConfiguration.class);

public static final String DEFAULT_CONFIG_FILE_PATH = System.getProperty("user.home")
+ "/config/org.opencadc.science-portal.properties";

+ "/config/org.opencadc.science-portal.properties";
private static final Logger LOGGER = Logger.getLogger(ApplicationConfiguration.class);
private final Configuration configuration;
private final String filePath;

Expand All @@ -55,7 +50,8 @@ public ApplicationConfiguration() {

final Parameters parameters = new Parameters();
final FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(parameters.properties().setFileName(filePath));
new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(
parameters.properties().setFileName(filePath));

try {
combinedConfiguration.addConfiguration(builder.getConfiguration());
Expand Down Expand Up @@ -89,6 +85,7 @@ public String getTokenCacheURLString() {
/**
* Expected that the configuration is a forward slash list of tab labels.
* <a href="https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html">Apache Configuration reference</a>
*
* @return String array, never null.
*/
public String[] getTabLabels() {
Expand All @@ -104,7 +101,8 @@ public String[] getTabLabels() {

/**
* Pull the /applications header URLs.
* @return JSONObject of header URIs to URLs.
*
* @return JSONObject of header URIs to URLs.
*/
public JSONObject getHeaderURLs() {
final RegistryClient registryClient = new RegistryClient();
Expand Down Expand Up @@ -143,7 +141,7 @@ String getStringValue(final String key, final boolean required) {

if (required && !StringUtil.hasText(val)) {
throw new IllegalStateException("Configuration property " + key + " is missing or invalid at "
+ this.filePath);
+ this.filePath);
} else {
return val;
}
Expand Down Expand Up @@ -175,8 +173,8 @@ public String getOIDCScope() {

public boolean isOIDCConfigured() {
return StringUtil.hasText(getOIDCClientID()) && StringUtil.hasText(getOIDCClientSecret())
&& StringUtil.hasText(getOIDCCallbackURI()) && StringUtil.hasText(getOIDCScope())
&& StringUtil.hasText(getTokenCacheURLString());
&& StringUtil.hasText(getOIDCCallbackURI()) && StringUtil.hasText(getOIDCScope())
&& StringUtil.hasText(getTokenCacheURLString());
}

public Client getOIDCClient() throws IOException {
Expand Down
Loading

0 comments on commit 1b762f5

Please sign in to comment.