/** * Legacy binary compatibility method. * @param p the property. * @throws IOException if the folder could not be saved. * @deprecated use {@link #addProperty(AbstractFolderProperty)} instead */ @Deprecated public void addProperty(FolderProperty<?> p) throws IOException { addProperty((AbstractFolderProperty) p); }
/** * Legacy binary compatibility method. * @param p the property. * @throws IOException if the folder could not be saved. * @deprecated use {@link #addProperty(AbstractFolderProperty)} instead */ @Deprecated public void addProperty(FolderProperty<?> p) throws IOException { addProperty((AbstractFolderProperty) p); }
ConfigFileStore getStore() { // TODO only add property when its really needed (eg. don't add it if there is no config to be saved) FolderConfigFileProperty folderConfigFileProperty = folder.getProperties().get(FolderConfigFileProperty.class); if(folderConfigFileProperty == null) { folderConfigFileProperty = new FolderConfigFileProperty(folder); try { folder.addProperty(folderConfigFileProperty); } catch (IOException e) { throw new RuntimeException(e); } } return folderConfigFileProperty; }
folder.addProperty(new FolderCredentialsProvider.FolderCredentialsProperty(new DomainCredentials[0])); r.jenkins.reload(); folder.addProperty(new com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty(grantedPermissions));
@Test public void grandParentOverride() throws Exception { Folder grandParent = j.createProject(Folder.class); getFolderStore(grandParent).addCredentials(Domain.global(), grandParentCred); grandParent.addProperty(new FolderConfig("parent_docker", "https://parent.registry", grandParentCred.getId())); Folder parent = grandParent.createProject(Folder.class, "testParent"); //Can be static since grandParent should be unique getFolderStore(parent).addCredentials(Domain.global(), folderCred); parent.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId())); expect("declarativeDockerConfig") .inFolder(parent) .runFromRepo(false) .logContains("Docker Label is: folder_docker", "Registry URL is: https://folder.registry", "Registry Creds ID is: " + folderCred.getId()) .logNotContains("Docker Label is: parent_docker", "Registry URL is: https://parent.registry", "Registry Creds ID is: " + grandParentCred.getId()).go(); }
@Issue("JENKINS-32487") @Test public void shouldAssignPropertyOwnerOnCreationAndReload() throws Exception { Folder folder = r.jenkins.createProject(Folder.class, "myFolder"); ProjectMatrixAuthorizationStrategy as = new ProjectMatrixAuthorizationStrategy(); // Need to do this to avoid JENKINS-9774 as.add(Jenkins.ADMINISTER, "alice"); r.jenkins.setAuthorizationStrategy(as); // We add a stub property to generate the persisted list // Then we ensure owner is being assigned properly. folder.addProperty(new FolderCredentialsProvider.FolderCredentialsProperty(new DomainCredentials[0])); assertPropertyOwner("After property add", folder, FolderCredentialsProvider.FolderCredentialsProperty.class); // Reload and ensure that the property owner is set r.jenkins.reload(); Folder reloadedFolder = r.jenkins.getItemByFullName("myFolder", Folder.class); assertPropertyOwner("After reload", reloadedFolder, FolderCredentialsProvider.FolderCredentialsProperty.class); }
@Test public void directParent() throws Exception { Folder folder = j.createProject(Folder.class); getFolderStore(folder).addCredentials(Domain.global(), folderCred); folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId())); expect("declarativeDockerConfig") .inFolder(folder) .runFromRepo(false) .logContains("Docker Label is: folder_docker", "Registry URL is: https://folder.registry", "Registry Creds ID is: " + folderCred.getId()).go(); }
@Test public void grandParent() throws Exception { Folder grandParent = j.createProject(Folder.class); getFolderStore(grandParent).addCredentials(Domain.global(), grandParentCred); grandParent.addProperty(new FolderConfig("parent_docker", "https://parent.registry", grandParentCred.getId())); Folder parent = grandParent.createProject(Folder.class, "testParent"); //Can be static since grandParent should be unique expect("declarativeDockerConfig") .inFolder(parent) .runFromRepo(false) .logContains("Docker Label is: parent_docker", "Registry URL is: https://parent.registry", "Registry Creds ID is: " + grandParentCred.getId()).go(); }
@Test public void withDefaults() throws Exception { Folder folder = j.createProject(Folder.class); getFolderStore(folder).addCredentials(Domain.global(), folderCred); getFolderStore(folder).addCredentials(Domain.global(), grandParentCred); folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId())); expect("declarativeDockerConfigWithOverride") .inFolder(folder) .runFromRepo(false) .logContains("Docker Label is: other-label", "Registry URL is: https://other.registry", "Registry Creds ID is: " + grandParentCred.getId()).go(); }
@BeforeClass public static void setup() throws Exception { CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next(); String usernamePasswordCredentialsId = "FOOcredentials"; UsernamePasswordCredentialsImpl usernamePassword = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, usernamePasswordCredentialsId, "sample", usernamePasswordUsername, usernamePasswordPassword); store.addCredentials(Domain.global(), usernamePassword); StringCredentialsImpl mixedEnvCred1 = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred1Id, "test", Secret.fromString(mixedEnvCred1Secret)); store.addCredentials(Domain.global(), mixedEnvCred1); UsernamePasswordCredentialsImpl mixedEnvCred2 = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred2Id, "sample", mixedEnvCred2U, mixedEnvCred2P); store.addCredentials(Domain.global(), mixedEnvCred2); StringCredentialsImpl mixedEnvCred3 = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred3Id, "test", Secret.fromString(mixedEnvCred3Secret)); store.addCredentials(Domain.global(), mixedEnvCred3); FileCredentialsImpl fileCred = new FileCredentialsImpl(CredentialsScope.GLOBAL, fileCredId, "test", fileCredName, SecretBytes.fromBytes(fileCredContent.getBytes())); store.addCredentials(Domain.global(), fileCred); FileCredentialsImpl otherFileCred = new FileCredentialsImpl(CredentialsScope.GLOBAL, otherFileCredId, "test", otherFileCredName, SecretBytes.fromBytes(otherFileCredContent.getBytes())); store.addCredentials(Domain.global(), otherFileCred); folder = j.jenkins.createProject(Folder.class, "testFolder"); folder.addProperty(new FolderCredentialsProvider.FolderCredentialsProperty(new DomainCredentials[0])); j.configRoundtrip(folder); CredentialsStore folderStore = folder.getProperties().get(FolderCredentialsProvider.FolderCredentialsProperty.class).getStore(); StringCredentialsImpl sc = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred1Id, "test", Secret.fromString(mixedEnvInFolderCred1Secret)); folderStore.addCredentials(Domain.global(), sc); UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred2Id, "sample", mixedEnvInFoldercred2U, mixedEnvInFolderCred2P); folderStore.addCredentials(Domain.global(), c); SSHUserPrivateKey k = new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, "sshCred1", "bobby", new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource("abc123"), null, "sample"); store.addCredentials(Domain.global(), k); }
@Test public void directParentNotSystem() throws Exception { GlobalConfig.get().setDockerLabel("config_docker"); GlobalConfig.get().setRegistry(new DockerRegistryEndpoint("https://docker.registry", globalCred.getId())); Folder folder = j.createProject(Folder.class); getFolderStore(folder).addCredentials(Domain.global(), folderCred); folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId())); expect("declarativeDockerConfig") .inFolder(folder) .runFromRepo(false) .logContains("Docker Label is: folder_docker", "Registry URL is: https://folder.registry", "Registry Creds ID is: " + folderCred.getId()) .logNotContains("Docker Label is: config_docker", "Registry URL is: https://docker.registry", "Registry Creds ID is: " + globalCred.getId()).go(); }