-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration as code support (#147)
* Bump jenkins core baseline * Fix tests * Configuration as code support * Rerun CI * Remove unused var * Use released version of JCasC * Restore test * Try bump jcasc version * Small tweaks, trying to fix windows build * Downgrade to compatible core version
- Loading branch information
Showing
5 changed files
with
109 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ | |
.settings | ||
|
||
*.idea | ||
*.iml | ||
*.iml | ||
index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/test/java/com/microsoftopentechnologies/windowsazurestorage/ConfigAsCodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.microsoftopentechnologies.windowsazurestorage; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsScope; | ||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider; | ||
import com.microsoftopentechnologies.windowsazurestorage.helper.AzureCredentials; | ||
import hudson.ExtensionList; | ||
import io.jenkins.plugins.casc.ConfigurationContext; | ||
import io.jenkins.plugins.casc.ConfiguratorRegistry; | ||
import io.jenkins.plugins.casc.misc.ConfiguredWithCode; | ||
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; | ||
import io.jenkins.plugins.casc.model.CNode; | ||
import io.jenkins.plugins.casc.model.Mapping; | ||
import io.jenkins.plugins.casc.support.credentials.CredentialsRootConfigurator; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class ConfigAsCodeTest { | ||
|
||
@Rule | ||
public JenkinsConfiguredWithCodeRule j = new JenkinsConfiguredWithCodeRule(); | ||
|
||
@Test | ||
@ConfiguredWithCode("configuration-as-code.yml") | ||
public void should_support_configuration_as_code() { | ||
AzureCredentials credentials = (AzureCredentials) SystemCredentialsProvider.getInstance().getCredentials() | ||
.get(0); | ||
|
||
assertEquals(credentials.getScope(), CredentialsScope.GLOBAL); | ||
assertEquals(credentials.getDescription(), "Account"); | ||
assertEquals(credentials.getStorageAccountName(), "a-storage-account"); | ||
assertEquals(credentials.getBlobEndpointURL(), "https://blob.core.windows.net/"); | ||
assertEquals(credentials.getId(), "storage-account"); | ||
assertNotNull(credentials.getStorageKey()); | ||
} | ||
|
||
@Test | ||
@ConfiguredWithCode("configuration-as-code.yml") | ||
public void export_configuration() throws Exception { | ||
ConfiguratorRegistry registry = ConfiguratorRegistry.get(); | ||
ConfigurationContext context = new ConfigurationContext(registry); | ||
|
||
CredentialsRootConfigurator root = ExtensionList | ||
.lookupSingleton(CredentialsRootConfigurator.class); | ||
final CNode node = root.describe(root.getTargetComponent(context), context); | ||
|
||
assertNotNull(node); | ||
Mapping mapping = node.asMapping().get("system") | ||
.asMapping() | ||
.get("domainCredentials") | ||
.asSequence() | ||
.get(0) | ||
.asMapping() | ||
.get("credentials") | ||
.asSequence() | ||
.get(0) | ||
.asMapping() | ||
.get("azureStorageAccount") | ||
.asMapping(); | ||
|
||
assertEquals(mapping.getScalarValue("scope"), "GLOBAL"); | ||
assertEquals(mapping.getScalarValue("description"), "Account"); | ||
assertEquals(mapping.getScalarValue("storageAccountName"), "a-storage-account"); | ||
assertEquals(mapping.getScalarValue("blobEndpointURL"), "https://blob.core.windows.net/"); | ||
assertEquals(mapping.getScalarValue("id"), "storage-account"); | ||
assertNotNull(mapping.getScalarValue("storageKey")); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...est/resources/com/microsoftopentechnologies/windowsazurestorage/configuration-as-code.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
credentials: | ||
system: | ||
domainCredentials: | ||
- credentials: | ||
- azureStorageAccount: | ||
blobEndpointURL: "https://blob.core.windows.net/" | ||
description: "Account" | ||
id: "storage-account" | ||
scope: GLOBAL | ||
storageAccountName: "a-storage-account" | ||
storageKey: "Password12" |