use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processSecrets.
/**
* Process Secrets annotations.
*
* @param attachmentNode Attachment Node
* @return List of @{@link SecretModel} objects
*/
Set<SecretModel> processSecrets(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<SecretModel> secrets = 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) {
SecretModel secretModel = new SecretModel();
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:
secretModel.setName(getValidName(annotationValue));
break;
case mountPath:
secretModel.setMountPath(annotationValue);
break;
case data:
List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
secretModel.setData(getDataForSecret(data));
break;
case readOnly:
secretModel.setReadOnly(Boolean.parseBoolean(annotationValue));
break;
default:
break;
}
}
secrets.add(secretModel);
}
}
return secrets;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project kubernetes by ballerinax.
the class KubernetesAnnotationProcessor method processServiceAnnotation.
/**
* Process annotations and create service model object.
*
* @param endpointName ballerina service name
* @param attachmentNode annotation attachment node.
* @return Service model object
*/
ServiceModel processServiceAnnotation(String endpointName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
ServiceModel serviceModel = new ServiceModel();
List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
ServiceConfiguration serviceConfiguration = ServiceConfiguration.valueOf(keyValue.getKey().toString());
String annotationValue = resolveValue(keyValue.getValue().toString());
switch(serviceConfiguration) {
case name:
serviceModel.setName(getValidName(annotationValue));
break;
case labels:
serviceModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
break;
case serviceType:
serviceModel.setServiceType(annotationValue);
break;
case port:
serviceModel.setPort(Integer.parseInt(annotationValue));
break;
default:
break;
}
}
if (serviceModel.getName() == null) {
serviceModel.setName(getValidName(endpointName) + SVC_POSTFIX);
}
return serviceModel;
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class AnnotationDesugar method generateAnnotations.
private void generateAnnotations(AnnotatableNode node, String key, BLangFunction target, BLangVariable annMapVar) {
if (node.getAnnotationAttachments().size() == 0) {
return;
}
BLangVariable entryVar = createAnnotationMapEntryVar(key, annMapVar, target.body, target.symbol);
int annCount = 0;
for (AnnotationAttachmentNode attachment : node.getAnnotationAttachments()) {
initAnnotation((BLangAnnotationAttachment) attachment, entryVar, target.body, target.symbol, annCount++);
}
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class AnnotationDesugar method initAnnotation.
private void initAnnotation(BLangAnnotationAttachment attachment, BLangVariable annotationMapEntryVar, BLangBlockStmt target, BSymbol parentSymbol, int index) {
BLangVariable annotationVar = null;
if (attachment.annotationSymbol.attachedType != null) {
// create: AttachedType annotationVar = { annotation-expression }
annotationVar = ASTBuilderUtil.createVariable(attachment.pos, attachment.annotationName.value, attachment.annotationSymbol.attachedType.type);
annotationVar.expr = attachment.expr;
ASTBuilderUtil.defineVariable(annotationVar, parentSymbol, names);
ASTBuilderUtil.createVariableDefStmt(attachment.pos, target).var = annotationVar;
}
// create: annotationMapEntryVar["name$index"] = annotationVar;
BLangAssignment assignmentStmt = ASTBuilderUtil.createAssignmentStmt(target.pos, target);
if (annotationVar != null) {
assignmentStmt.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationVar.symbol);
} else {
assignmentStmt.expr = ASTBuilderUtil.createLiteral(target.pos, symTable.nullType, null);
}
BLangIndexBasedAccess indexAccessNode = (BLangIndexBasedAccess) TreeBuilder.createIndexBasedAccessNode();
indexAccessNode.pos = target.pos;
indexAccessNode.indexExpr = ASTBuilderUtil.createLiteral(target.pos, symTable.stringType, attachment.annotationSymbol.bvmAlias() + "$" + index);
indexAccessNode.expr = ASTBuilderUtil.createVariableRef(target.pos, annotationMapEntryVar.symbol);
indexAccessNode.type = annotationMapEntryVar.symbol.type;
assignmentStmt.varRefs.add(indexAccessNode);
}
use of org.wso2.carbon.attachment.mgt.api.attachment.Attachment in project ballerina by ballerina-lang.
the class Util method createNestedPartRequest.
/**
* Two body parts have been wrapped inside multipart/mixed which in turn acts as the child part for the parent
* multipart/form-data.
*
* @param path Resource path
* @return HTTPTestRequest with nested parts as the entity body
*/
static HTTPTestRequest createNestedPartRequest(String path) {
List<Header> headers = new ArrayList<>();
String multipartDataBoundary = MimeUtil.getNewMultipartDelimiter();
String multipartMixedBoundary = MimeUtil.getNewMultipartDelimiter();
headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), "multipart/form-data; boundary=" + multipartDataBoundary));
String multipartBodyWithNestedParts = "--" + multipartDataBoundary + "\r\n" + "Content-Disposition: form-data; name=\"parent1\"" + "\r\n" + "Content-Type: text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "Parent Part" + "\r\n" + "--" + multipartDataBoundary + "\r\n" + "Content-Disposition: form-data; name=\"parent2\"" + "\r\n" + "Content-Type: multipart/mixed; boundary=" + multipartMixedBoundary + "\r\n" + "\r\n" + "--" + multipartMixedBoundary + "\r\n" + "Content-Disposition: attachment; filename=\"file-02.txt\"" + "\r\n" + "Content-Type: text/plain" + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n" + "\r\n" + "Child Part 1" + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "\r\n" + "Content-Disposition: attachment; filename=\"file-02.txt\"" + "\r\n" + "Content-Type: text/plain" + "\r\n" + "Content-Transfer-Encoding: binary" + "\r\n" + "\r\n" + "Child Part 2" + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "--" + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n";
return MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, multipartBodyWithNestedParts);
}
Aggregations