Skip to content

Commit

Permalink
Fix AzureBlobAction [FIXED JENKINS-42726]
Browse files Browse the repository at this point in the history
  • Loading branch information
clguiman committed Mar 14, 2017
1 parent da1ee43 commit f8e8b7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
@@ -1,8 +1,7 @@
package com.microsoftopentechnologies.windowsazurestorage;

import com.microsoftopentechnologies.windowsazurestorage.WAStoragePublisher.WAStorageDescriptor;
import com.microsoftopentechnologies.windowsazurestorage.beans.StorageAccountInfo;
import com.microsoftopentechnologies.windowsazurestorage.helper.Utils;
import com.microsoftopentechnologies.windowsazurestorage.helper.AzureCredentials;
import hudson.model.Api;
import hudson.model.Run;
import hudson.model.RunAction;
Expand All @@ -25,16 +24,18 @@ public class AzureBlobAction implements RunAction {
private final boolean allowAnonymousAccess;
private final AzureBlob zipArchiveBlob;
private final List<AzureBlob> individualBlobs;
private final String storageCredentialId;

public AzureBlobAction(Run build, String storageAccountName, String containerName,
List<AzureBlob> individualBlobs, AzureBlob zipArchiveBlob,
boolean allowAnonymousAccess) {
boolean allowAnonymousAccess, String storageCredentialId) {
this.storageAccountName = storageAccountName;
this.containerName = containerName;
this.individualBlobs = individualBlobs;
this.allowAnonymousAccess = allowAnonymousAccess;
this.zipArchiveBlob = zipArchiveBlob;
this.build = build;
this.storageCredentialId = storageCredentialId;
}

public Run<?, ?> getBuild() {
Expand Down Expand Up @@ -90,20 +91,16 @@ public boolean getAllowAnonymousAccess() {
return allowAnonymousAccess;
}

private WAStoragePublisher.WAStorageDescriptor getWAStorageDescriptor() {
WAStoragePublisher.WAStorageDescriptor desc = Utils.getJenkinsInstance().getDescriptorByType(WAStoragePublisher.WAStorageDescriptor.class);
return desc;
}

public void doProcessDownloadRequest(final StaplerRequest request, final StaplerResponse response) throws IOException, ServletException {
WAStorageDescriptor storageDesc = getWAStorageDescriptor();
StorageAccountInfo accountInfo = storageDesc.getStorageAccount(storageAccountName);
AzureCredentials.StorageAccountCredential accountCredentials = AzureCredentials.getStorageCreds(storageCredentialId, storageAccountName);

if (accountInfo == null) {
if (accountCredentials == null) {
response.sendError(500, "Azure Storage account global configuration is missing");
return;
}

StorageAccountInfo accountInfo = AzureCredentials.convertToStorageAccountInfo(accountCredentials);

if (!allowAnonymousAccess && isAnonymousAccess(Jenkins.getAuthentication())) {
String url = request.getOriginalRequestURI();
response.sendRedirect("/login?from=" + url);
Expand Down
Expand Up @@ -333,7 +333,7 @@ public synchronized void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath ws, @
listener.getLogger().println(Messages.WAStoragePublisher_files_uploaded_count(filesUploaded));

run.getActions().add(new AzureBlobAction(run, strAcc.getStorageAccName(),
expContainerName, individualBlobs, zipArchiveBlob, allowAnonymousAccess));
expContainerName, individualBlobs, zipArchiveBlob, allowAnonymousAccess, storageCredentialId));
}
} catch (Exception e) {
e.printStackTrace(listener.error(Messages
Expand Down

0 comments on commit f8e8b7a

Please sign in to comment.