private static String createCredentials(String serverAPIUrl, StandardCredentials credentials) throws Exception { List<DomainSpecification> specifications = new ArrayList<DomainSpecification>(2); URI serverUri = new URI(serverAPIUrl); if (serverUri.getPort() > 0) { specifications.add(new HostnamePortSpecification(serverUri.getHost() + ":" + serverUri.getPort(), null)); } else { specifications.add(new HostnameSpecification(serverUri.getHost(), null)); } specifications.add(new SchemeSpecification(serverUri.getScheme())); String path = serverUri.getPath(); if (StringUtils.isEmpty(path)) { path = "/"; } specifications.add(new PathSpecification(path, null, false)); Domain domain = new Domain(serverUri.getHost(), "Auto generated credentials domain", specifications); CredentialsStore provider = new SystemCredentialsProvider.StoreImpl(); provider.addDomain(domain, credentials); return credentials.getId(); }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getId() + (description != null ? " (" + description + ")" : ""); } }
/** * Gets the description of the {@link Credentials}. * * @return the description of the {@link Credentials}. */ @Exported public String getDescription() { return credentials instanceof StandardCredentials ? ((StandardCredentials) credentials).getDescription() : null; }
public String iconClassName() { if (StringUtils.isBlank(value)) { return ""; } final Run run = Stapler.getCurrentRequest().findAncestorObject(Run.class); if (run == null) { throw new IllegalStateException("Should only be called from value.jelly"); } StandardCredentials c = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(value)); if (c != null) { return c.getDescriptor().getIconClassName(); } c = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), Jenkins.getAuthentication(), Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(value)); if (c != null) { return c.getDescriptor().getIconClassName(); } return "icon-credentials-credential"; }
/** * Gets the description of the {@link Credentials}. * * @return the description of the {@link Credentials}. */ @Exported public String getDescription() { return credentials instanceof StandardCredentials ? ((StandardCredentials) credentials).getDescription() : null; }
public String iconClassName() { if (StringUtils.isBlank(value)) { return ""; } final Run run = Stapler.getCurrentRequest().findAncestorObject(Run.class); if (run == null) { throw new IllegalStateException("Should only be called from value.jelly"); } StandardCredentials c = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(value)); if (c != null) { return c.getDescriptor().getIconClassName(); } c = CredentialsMatchers.firstOrNull( CredentialsProvider.lookupCredentials(StandardCredentials.class, run.getParent(), Jenkins.getAuthentication(), Collections.<DomainRequirement>emptyList()), CredentialsMatchers.withId(value)); if (c != null) { return c.getDescriptor().getIconClassName(); } return "icon-credentials-credential"; }
@SuppressWarnings("unused") @RequirePOST public FormValidation doCreateTokenByPassword( @QueryParameter String apiUrl, @QueryParameter String login, @QueryParameter String password) { Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER); try { GHAuthorization token = createToken(login, password, defaultIfBlank(apiUrl, GITHUB_URL)); StandardCredentials credentials = createCredentials(apiUrl, token.getToken(), login); return FormValidation.ok( "Created credentials with id %s (can use it for GitHub Server Config)", credentials.getId()); } catch (IOException e) { return FormValidation.error(e, "Can't create GH token for %s - %s", login, e.getMessage()); } }
/** * {@inheritDoc} */ @NonNull @Override public String getName(@NonNull StandardCredentials c) { String description = Util.fixEmptyAndTrim(c.getDescription()); return c.getId() + (description != null ? " (" + description + ")" : ""); } }
/** * Returns the {@link StandardCredentials#getDescription()} of the {@link #credentials}. * * @return the {@link StandardCredentials#getDescription()} of the {@link #credentials}. * @throws IOException if there was an issue with formatting this using the markup formatter. */ public String getDescription() throws IOException { return credentials instanceof StandardCredentials ? Jenkins.getActiveInstance().getMarkupFormatter() .translate(((StandardCredentials) credentials).getDescription()) : null; }
/*package*/ void migrateCredentials(SubversionSCM.DescriptorImpl descriptor) throws IOException { Iterable<CredentialsStore> it = CredentialsProvider.lookupStores(project); if (it != null && it.iterator().hasNext()) { CredentialsStore store = it.iterator().next(); for (Map.Entry<String, Credential> e : credentials.entrySet()) { StandardCredentials credential = descriptor.migrateCredentials(store, e.getKey(), e.getValue()); ModuleLocation[] locations = ((SubversionSCM) project.getScm()).getLocations(); for (int i = 0; i < locations.length; i++) { try { if (e.getKey().contains(locations[i].getSVNURL().getHost())) { locations[i].setCredentialsId(credential.getId()); break; } } catch (SVNException ex) { // Should not happen, but... LOGGER.log(WARNING, "Repository location with a malformed URL: " + locations[i].remote, ex); } } } } } }
/** * Returns the {@link StandardCredentials#getDescription()} of the {@link #credentials}. * * @return the {@link StandardCredentials#getDescription()} of the {@link #credentials}. * @throws IOException if there was an issue with formatting this using the markup formatter. */ public String getDescription() throws IOException { return credentials instanceof StandardCredentials ? Jenkins.getActiveInstance().getMarkupFormatter() .translate(((StandardCredentials) credentials).getDescription()) : null; }
credentials.getId());
this.data = this.cache.getHashMap(credentials == null ? "data" : "data-" + credentials.getId()); cache.commit(); success = true;
@Override public GitHubServerConfig apply(Credential input) { LOGGER.info("Migrate GitHub Plugin creds for {} {}", input.getUsername(), input.getApiUrl()); GitHubTokenCredentialsCreator creator = Jenkins.getInstance().getDescriptorByType(GitHubTokenCredentialsCreator.class); StandardCredentials credentials = creator.createCredentials( input.getApiUrl(), input.getOauthAccessToken(), input.getUsername() ); GitHubServerConfig gitHubServerConfig = new GitHubServerConfig(credentials.getId()); gitHubServerConfig.setApiUrl(input.getApiUrl()); return gitHubServerConfig; } };