public StackMetaData(String stackName, String stackUUID, boolean isSystem, Account account) { this.name = stackName; this.uuid = stackUUID; this.environment_name = account.getName(); this.environment_uuid = account.getUuid(); this.system = isSystem; this.metadata_kind = "stack"; }
public AccountPolicy(Account account, Account authenticatedAsAccount, Set<Identity> identities, PolicyOptions options) { super(account.getId(), authenticatedAsAccount.getId(), account.getName(), identities, options); }
String targetAgentUri = RegionUtil.getTargetAgentUri(localRegion.getName(), account.getName(), agent.getUuid(), targetResourceAccount.getUuid()); log.info(String.format("Creating external agent with uri [%s] in environment [%s] in region [%s]", targetAgentUri,
public static ExternalAccountLink getAccountLinkForExternal(Region targetRegion, ExternalProject targetResourceAccount, Account localAccount, JsonMapper jsonMapper) throws IOException { String uri = String.format("%s/v2-beta/accountLinks?accountId=%s&linkedAccount=%s&external=false", getUrl(targetRegion), targetResourceAccount.getId(), localAccount.getName()); Request req = Request.Get(uri); setHeaders(req, targetRegion); return req.execute().handleResponse(new ResponseHandler<ExternalAccountLink>() { @Override public ExternalAccountLink handleResponse(HttpResponse response) throws ClientProtocolException, IOException { if (response.getStatusLine().getStatusCode() != 200) { return null; } for (ExternalAccountLink link : jsonMapper.readValue(response.getEntity().getContent(), ExternalAccountLinkData.class).data) { List<String> invalidStates = Arrays.asList(CommonStatesConstants.REMOVED, CommonStatesConstants.REMOVING); if (invalidStates.contains(link.getState())) { continue; } if (link.getLinkedAccountUuid().equalsIgnoreCase(localAccount.getUuid())) { return link; } } return null; } }); }
data.put("accountId", targetResourceAccount.getId()); data.put("external", "true"); data.put("linkedAccount", localAccount.getName()); data.put("linkedRegion", externalRegion.getName()); data.put("linkedRegionId", externalRegion.getId());
public static ExternalAccountLink getExternalAccountLink(Region targetRegion, ExternalProject targetResourceAccount, Account localAccount, JsonMapper jsonMapper) throws IOException { String uri = String.format("%s/v2-beta/accountLinks?accountId=%s&linkedAccount=%s&external=true", getUrl(targetRegion), targetResourceAccount.getId(), localAccount.getName()); Request req = Request.Get(uri); setHeaders(req, targetRegion); return req.execute().handleResponse(new ResponseHandler<ExternalAccountLink>() { @Override public ExternalAccountLink handleResponse(HttpResponse response) throws ClientProtocolException, IOException { if (response.getStatusLine().getStatusCode() != 200) { return null; } for (ExternalAccountLink link : jsonMapper.readValue(response.getEntity().getContent(), ExternalAccountLinkData.class).data) { List<String> invalidStates = Arrays.asList(CommonStatesConstants.REMOVED, CommonStatesConstants.REMOVING); if (invalidStates.contains(link.getState())) { continue; } if (link.getLinkedAccountUuid().equalsIgnoreCase(localAccount.getUuid())) { return link; } } return null; } }); }
List<Account> projectsFiltered = new ArrayList<>(); for (Account project : projects) { if (StringUtils.isNotBlank(name) && !name.equalsIgnoreCase(project.getName())) { continue;
@Override public void fetchEnvironment(final MetaHelperInfo helperInfo, final OutputStream os) { Account env = helperInfo.getAccount(); EnvironmentMetaData data = new EnvironmentMetaData(StringUtils.lowerCase(env.getName()), env.getUuid(), StringUtils.lowerCase(helperInfo.getRegionName())); writeToJson(os, data); }
protected void saveInContext(ApiRequest request, Policy policy, SchemaFactory schemaFactory, Account authorizedAccount) { if (schemaFactory != null) { request.setSchemaFactory(schemaFactory); } String accountId = (String) ApiContext.getContext().getIdFormatter().formatId(objectManager.getType(Account.class), policy.getAccountId()); request.getServletContext().getResponse().addHeader(ACCOUNT_ID_HEADER, accountId); String userId = (String) ApiContext.getContext().getIdFormatter().formatId(objectManager.getType(Account.class), policy.getAuthenticatedAsAccountId()); request.getServletContext().getResponse().addHeader(USER_ID_HEADER, userId); request.getServletContext().getResponse().addHeader(ACCOUNT_KIND_HEADER, authorizedAccount.getKind()); request.getServletContext().getResponse().addHeader(ACCOUNT_NAME_HEADER, authorizedAccount.getName()); ApiContext.getContext().setPolicy(policy); }
@Override public Identity getIdentity(Long id, IdFormatter idFormatter) { Account account = getAccountById(id); if (account == null || account.getKind().equalsIgnoreCase(ProjectConstants.TYPE) || !accountDao.isActiveAccount(account)) { return null; } Credential credential = create() .selectFrom(CREDENTIAL) .where(CREDENTIAL.KIND.equalIgnoreCase(CredentialConstants.KIND_PASSWORD) .and(CREDENTIAL.ACCOUNT_ID.eq(id)) .and(CREDENTIAL.STATE.equalIgnoreCase(CommonStatesConstants.ACTIVE))).fetchAny(); String accountId = idFormatter != null ? (String) idFormatter.formatId(objectManager.getType(Account.class), account.getId()) : String.valueOf(id); return new Identity(ProjectConstants.RANCHER_ID, accountId, account.getName(), null, null, credential == null ? null : credential.getPublicValue(), false); }
/** * {@inheritDoc} */ @Override public void from(io.cattle.platform.core.model.Account from) { setId(from.getId()); setName(from.getName()); setKind(from.getKind()); setUuid(from.getUuid()); setDescription(from.getDescription()); setState(from.getState()); setCreated(from.getCreated()); setRemoved(from.getRemoved()); setRemoveTime(from.getRemoveTime()); setData(from.getData()); setExternalId(from.getExternalId()); setExternalIdType(from.getExternalIdType()); setHealthState(from.getHealthState()); setProjectTemplateId(from.getProjectTemplateId()); setDefaultNetworkId(from.getDefaultNetworkId()); setVersion(from.getVersion()); setRevision(from.getRevision()); }