Skip to content

Commit

Permalink
Make CSP compatible and remove YUI (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
timja authored Oct 31, 2024
1 parent 405255f commit 6496dbf
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 72 deletions.
15 changes: 8 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/azure-storage-plugin</gitHubRepo>
<jenkins.version>2.387.3</jenkins.version>
<jenkins.baseline>2.452</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
</properties>

<licenses>
Expand All @@ -29,8 +30,8 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.387.x</artifactId>
<version>2543.vfb_1a_5fb_9496d</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3559.vb_5b_81183b_d23</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -107,11 +108,11 @@
</dependency>
</dependencies>

<scm>
<connection>scm:git:ssh://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:git@github.com:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<scm child.scm.connection.inherit.append.path="false" child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">
<connection>scm:git:https://github.com/${gitHubRepo}</connection>
<developerConnection>scm:git:https://github.com/${gitHubRepo}</developerConnection>
<tag>${scmTag}</tag>
<url>https://github.com/${gitHubRepo}</url>
</scm>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
import hudson.util.CopyOnWriteList;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
Expand All @@ -65,16 +74,6 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;

public class WAStoragePublisher extends Recorder implements SimpleBuildStep {
private static final Logger LOGGER = Logger.getLogger(WAStoragePublisher.class.getName());

Expand Down Expand Up @@ -800,21 +799,18 @@ public ListBoxModel doFillStorageCredentialIdItems(@AncestorInPath Item owner) {
@Restricted(NoExternalUse.class)
public List<String> getStorageCredentials() {
Item owner = null;
ListBoxModel allCreds = new StandardListBoxModel().withAll(
CredentialsProvider.lookupCredentials(
AzureStorageAccount.class,
owner,
ACL.SYSTEM,
Collections.<DomainRequirement>emptyList()));
ArrayList<Object> res = new ArrayList<Object>();
List<String> allStorageCred = new ArrayList<String>();
for (int i = 0; i < allCreds.size(); i++) {
res.add(allCreds.get(i));
String eachStorageCredential = res.get(i).toString();
String eachStorageAccount = eachStorageCredential.substring(0, eachStorageCredential.indexOf('='));

allStorageCred.add(eachStorageAccount);

List<AzureStorageAccount> storageAccounts = CredentialsProvider.lookupCredentialsInItem(
AzureStorageAccount.class,
null,
ACL.SYSTEM2
);

List<String> allStorageCred = new ArrayList<>();
for (AzureStorageAccount storageAccount : storageAccounts) {
allStorageCred.add(
String.format("%s (%s)", storageAccount.getStorageAccountName(), storageAccount.getId())

Check warning on line 812 in src/main/java/com/microsoftopentechnologies/windowsazurestorage/WAStoragePublisher.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 803-812 are not covered by tests
);
}
return allStorageCred;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:sf="/lib/credentials" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="${%WindowsAzureStorage_title}" id="windows-azure-storage">
<f:entry title="${%entry_title}" >
<f:entry var="storageAccount" items="${descriptor.storageAccounts}" noAddButton="true" minimum="1">
<table width="102%">

<f:entry field="storageCredentialId" help="/plugin/windows-azure-storage/help-storageaccounts.html">
<div style="display: none; !important">
<sf:select class="display: none !important" expressionAllowed="false" />
</div>
</f:entry>
<j:set var="storagePublisher" value="${app.getDescriptorByName('com.microsoftopentechnologies.windowsazurestorage.WAStoragePublisher.WAStorageDescriptor')}"/>
<j:set var="storageCreds" value="${instance.getStorageCredentials()}"/>
</table>
<div align="left" style="font-size:110%">
<j:forEach var="storageCred" items="${storageCreds}">
<ul style="list-style-type: none;">
<li>
<label>${storageCred}</label>
</li>
</ul>
</j:forEach>
</div>
<div align="center">
<j:set var="credsAjaxURI" value="${rootURL}${instance.getAjaxURI()}"/>
<input type="button" class="yui-button" value="Add Storage Accounts" onclick="window.credentials.add('${credsAjaxURI}')" />
<p>
<a href="credentials/store/system/domain/_/" target="_blank">Manage Storage Accounts in Credential Store</a>
</p>
</div>
</f:entry>
</f:entry>
</f:section>
<j:jelly xmlns:j="jelly:core"
xmlns:f="/lib/form" xmlns:st="jelly:stapler"
>
<f:section title="${%WindowsAzureStorage_title}">
<f:entry title="${%entry_title}" help="/plugin/windows-azure-storage/help-storageaccounts.html">
<j:set var="storageCreds" value="${instance.getStorageCredentials()}"/>
<div>
<j:forEach var="storageCred" items="${storageCreds}">
<ul>
<li>
<label>${storageCred}</label>
</li>
</ul>
</j:forEach>
</div>
<div>
<st:adjunct includes="lib.credentials.select.select"/>
<st:adjunct includes="lib.azure-storage.credentials"/>
<j:set var="credsAjaxURI" value="${rootURL}${instance.getAjaxURI()}"/>
<button
class="jenkins-button"
id="azure-storage-add-credentials"
data-credentials-uri="${credsAjaxURI}"
>
Add Storage Accounts
</button>
<p>
<a href="credentials/store/system/domain/_/" target="_blank">
Manage Storage Accounts in Credential Store
</a>
</p>
</div>
</f:entry>
</f:section>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WindowsAzureStorage_title=Microsoft Azure Storage Account Configuration
entry_title=Storage Account in the System (Storage Account names)
WindowsAzureStorage_title=Azure Storage Account
entry_title=Storage Accounts
rep_val_btn=Validate storage credentials
rep_val_btn_msg=Validation in progress...
rep_del_btn=Delete
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/global.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
WindowsAzureStorage_title=Microsoft Azure Storage Account Configuration
WindowsAzureStorage_title=Azure Storage Account
entry_title=Storage Account Details
rep_storageAccountName=Storage account name
rep_storageAccountKey=Storage account key
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/lib/azure-storage/credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
document.addEventListener('DOMContentLoaded', () => {
const button = document.getElementById("azure-storage-add-credentials")
const credentialsUri = button.dataset.credentialsUri
button.addEventListener('click', (e) => {
e.preventDefault();
window.credentials.add(credentialsUri)
})
})
Empty file.
9 changes: 4 additions & 5 deletions src/main/webapp/help-storageaccounts.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div>
The list of storage accounts configured within the Jenkins controller
<br />
Unique ids of each storage accounts are followed by the storage account names in brackets
<br />
Refresh the page after you have added a new storage account.
All storage accounts configured within the Jenkins controller
<br/>
Refresh the page after you have added a new storage account.
</div>

0 comments on commit 6496dbf

Please sign in to comment.