use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processSecureSocketAnnotation.
/**
* Extract key-store/trust-store file location from endpoint.
*
* @param endpointName Endpoint name
* @param secureSocketKeyValues secureSocket annotation struct
* @return List of @{@link SecretModel} objects
*/
Set<SecretModel> processSecureSocketAnnotation(String endpointName, List<BLangRecordLiteral.BLangRecordKeyValue> secureSocketKeyValues) throws KubernetesPluginException {
Set<SecretModel> secrets = new HashSet<>();
String keyStoreFile = null;
String trustStoreFile = null;
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : secureSocketKeyValues) {
// extract file paths.
String key = keyValue.getKey().toString();
if ("keyStore".equals(key)) {
keyStoreFile = extractFilePath(keyValue);
} else if ("trustStore".equals(key)) {
trustStoreFile = extractFilePath(keyValue);
}
}
if (keyStoreFile != null && trustStoreFile != null) {
if (getMountPath(keyStoreFile).equals(getMountPath(trustStoreFile))) {
// trust-store and key-store mount to same path
String keyStoreContent = readSecretFile(keyStoreFile);
String trustStoreContent = readSecretFile(trustStoreFile);
SecretModel secretModel = new SecretModel();
secretModel.setName(getValidName(endpointName) + "-secure-socket");
secretModel.setMountPath(getMountPath(keyStoreFile));
Map<String, String> dataMap = new HashMap<>();
dataMap.put(String.valueOf(Paths.get(keyStoreFile).getFileName()), keyStoreContent);
dataMap.put(String.valueOf(Paths.get(trustStoreFile).getFileName()), trustStoreContent);
secretModel.setData(dataMap);
secrets.add(secretModel);
return secrets;
}
}
if (keyStoreFile != null) {
String keyStoreContent = readSecretFile(keyStoreFile);
SecretModel secretModel = new SecretModel();
secretModel.setName(getValidName(endpointName) + "-keystore");
secretModel.setMountPath(getMountPath(keyStoreFile));
Map<String, String> dataMap = new HashMap<>();
dataMap.put(String.valueOf(Paths.get(keyStoreFile).getFileName()), keyStoreContent);
secretModel.setData(dataMap);
secrets.add(secretModel);
}
if (trustStoreFile != null) {
String trustStoreContent = readSecretFile(trustStoreFile);
SecretModel secretModel = new SecretModel();
secretModel.setName(getValidName(endpointName) + "-truststore");
secretModel.setMountPath(getMountPath(trustStoreFile));
Map<String, String> dataMap = new HashMap<>();
dataMap.put(String.valueOf(Paths.get(trustStoreFile).getFileName()), trustStoreContent);
secretModel.setData(dataMap);
secrets.add(secretModel);
}
return secrets;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processPersistentVolumeClaim.
/**
* Process PersistentVolumeClaim annotations.
*
* @param attachmentNode Attachment Node
* @return Set of @{@link ConfigMapModel} objects
*/
Set<PersistentVolumeClaimModel> processPersistentVolumeClaim(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<PersistentVolumeClaimModel> volumeClaimModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
List<BLangExpression> secretAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : secretAnnotation) {
PersistentVolumeClaimModel claimModel = new PersistentVolumeClaimModel();
List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
VolumeClaimConfig volumeMountConfig = VolumeClaimConfig.valueOf(annotation.getKey().toString());
String annotationValue = resolveValue(annotation.getValue().toString());
switch(volumeMountConfig) {
case name:
claimModel.setName(getValidName(annotationValue));
break;
case mountPath:
claimModel.setMountPath(annotationValue);
break;
case accessMode:
claimModel.setAccessMode(annotationValue);
break;
case volumeClaimSize:
claimModel.setVolumeClaimSize(annotationValue);
break;
case readOnly:
claimModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
volumeClaimModels.add(claimModel);
}
}
return volumeClaimModels;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processConfigMap.
/**
* Process ConfigMap annotations.
*
* @param attachmentNode Attachment Node
* @return Set of @{@link ConfigMapModel} objects
*/
Set<ConfigMapModel> processConfigMap(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<ConfigMapModel> configMapModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
List<BLangExpression> configAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
ConfigMapModel configMapModel = new ConfigMapModel();
List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
String annotationValue = resolveValue(annotation.getValue().toString());
switch(volumeMountConfig) {
case name:
configMapModel.setName(getValidName(annotationValue));
break;
case mountPath:
configMapModel.setMountPath(annotationValue);
break;
case isBallerinaConf:
configMapModel.setBallerinaConf(Boolean.parseBoolean(annotationValue));
break;
case data:
List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
configMapModel.setData(getDataForConfigMap(data));
break;
case readOnly:
configMapModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
configMapModels.add(configMapModel);
}
}
return configMapModels;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getSignatureInfoModel.
/**
* Get the required signature information filled model.
*
* @param bInvokableSymbol Invokable symbol
* @param signatureContext Signature operation context
* @return {@link SignatureInfoModel} SignatureInfoModel containing signature information
*/
private static SignatureInfoModel getSignatureInfoModel(BInvokableSymbol bInvokableSymbol, TextDocumentServiceContext signatureContext) {
Map<String, String> paramDescMap = new HashMap<>();
SignatureInfoModel signatureInfoModel = new SignatureInfoModel();
List<ParameterInfoModel> paramModels = new ArrayList<>();
String functionName = signatureContext.get(SignatureKeys.CALLABLE_ITEM_NAME);
CompilerContext compilerContext = signatureContext.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY);
BLangPackage bLangPackage = signatureContext.get(DocumentServiceKeys.LS_PACKAGE_CACHE_KEY).findPackage(compilerContext, bInvokableSymbol.pkgID);
BLangFunction blangFunction = bLangPackage.getFunctions().stream().filter(bLangFunction -> bLangFunction.getName().getValue().equals(functionName)).findFirst().orElse(null);
if (!blangFunction.getDocumentationAttachments().isEmpty()) {
// Get the first documentation attachment
BLangDocumentation bLangDocumentation = blangFunction.getDocumentationAttachments().get(0);
signatureInfoModel.setSignatureDescription(bLangDocumentation.documentationText.trim());
bLangDocumentation.attributes.forEach(attribute -> {
if (attribute.docTag.equals(DocTag.PARAM)) {
paramDescMap.put(attribute.documentationField.getValue(), attribute.documentationText.trim());
}
});
} else {
// TODO: Should be deprecated in due course
// Iterate over the attachments list and extract the attachment Description Map
blangFunction.getAnnotationAttachments().forEach(annotationAttachment -> {
BLangExpression expr = annotationAttachment.expr;
if (expr instanceof BLangRecordLiteral) {
List<BLangRecordLiteral.BLangRecordKeyValue> recordKeyValues = ((BLangRecordLiteral) expr).keyValuePairs;
for (BLangRecordLiteral.BLangRecordKeyValue recordKeyValue : recordKeyValues) {
BLangExpression key = recordKeyValue.key.expr;
BLangExpression value = recordKeyValue.getValue();
if (key instanceof BLangSimpleVarRef && ((BLangSimpleVarRef) key).getVariableName().getValue().equals("value") && value instanceof BLangLiteral) {
String annotationValue = ((BLangLiteral) value).getValue().toString();
if (annotationAttachment.getAnnotationName().getValue().equals("Param")) {
String paramName = annotationValue.substring(0, annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD));
String annotationDesc = annotationValue.substring(annotationValue.indexOf(UtilSymbolKeys.PKG_DELIMITER_KEYWORD) + 1).trim();
paramDescMap.put(paramName, annotationDesc);
} else if (annotationAttachment.getAnnotationName().getValue().equals("Description")) {
signatureInfoModel.setSignatureDescription(annotationValue);
}
}
}
}
});
}
bInvokableSymbol.getParameters().forEach(bVarSymbol -> {
ParameterInfoModel parameterInfoModel = new ParameterInfoModel();
parameterInfoModel.setParamType(bVarSymbol.getType().toString());
parameterInfoModel.setParamValue(bVarSymbol.getName().getValue());
parameterInfoModel.setDescription(paramDescMap.get(bVarSymbol.getName().getValue()));
paramModels.add(parameterInfoModel);
});
signatureInfoModel.setParameterInfoModels(paramModels);
return signatureInfoModel;
}
use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project ballerina by ballerina-lang.
the class SignatureHelpUtil method getFunctionSignatureHelp.
/**
* Get the functionSignatureHelp instance.
*
* @param context Signature help context
* @return {@link SignatureHelp} Signature help for the completion
*/
public static SignatureHelp getFunctionSignatureHelp(TextDocumentServiceContext context) {
// Get the functions List
List<SymbolInfo> functions = context.get(SignatureKeys.FILTERED_FUNCTIONS);
List<SignatureInformation> signatureInformationList = functions.stream().map(symbolInfo -> getSignatureInformation((BInvokableSymbol) symbolInfo.getScopeEntry().symbol, context)).filter(Objects::nonNull).collect(Collectors.toList());
SignatureHelp signatureHelp = new SignatureHelp();
signatureHelp.setSignatures(signatureInformationList);
signatureHelp.setActiveParameter(context.get(SignatureKeys.PARAMETER_COUNT));
signatureHelp.setActiveSignature(0);
return signatureHelp;
}
Aggregations