Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / packagetransformer / CbamVnfPackageBuilder.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
18
19 import com.google.common.io.ByteStreams;
20 import java.io.ByteArrayInputStream;
21 import java.io.ByteArrayOutputStream;
22 import java.io.IOException;
23 import java.util.zip.ZipEntry;
24 import java.util.zip.ZipInputStream;
25 import java.util.zip.ZipOutputStream;
26
27 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
28
29 /**
30  * Builds a CBAM VNF package capable to be deployed on ONAP from a CBAM package
31  */
32 public class CbamVnfPackageBuilder {
33
34     /**
35      * @param originalCbamVnfPackage  the original CBAM VNF package
36      * @param vnfdLocation            the location of the VNFD within the CBAM VNF package
37      * @param modifiedCbamVnfdContent the modified CBAM VNFD content
38      * @return the mod
39      */
40     public byte[] toModifiedCbamVnfPackage(byte[] originalCbamVnfPackage, String vnfdLocation, String modifiedCbamVnfdContent) throws IOException {
41         ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(originalCbamVnfPackage));
42         ByteArrayOutputStream result = new ByteArrayOutputStream();
43         ZipOutputStream out = new ZipOutputStream(result);
44         ZipEntry zipEntry;
45         while ((zipEntry = zipInputStream.getNextEntry()) != null) {
46             if (zipEntry.getName().matches(vnfdLocation)) {
47                 out.putNextEntry(new ZipEntry(vnfdLocation));
48                 out.write(modifiedCbamVnfdContent.getBytes());
49                 out.closeEntry();
50             } else {
51                 out.putNextEntry(new ZipEntry(zipEntry.getName()));
52                 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
53                 ByteStreams.copy(zipInputStream, byteArrayOutputStream);
54                 out.write(byteArrayOutputStream.toByteArray());
55                 out.closeEntry();
56             }
57         }
58         out.putNextEntry(new ZipEntry("javascript/cbam.pre.collectConnectionPoints.js"));
59         out.write(systemFunctions().loadFile("cbam.pre.collectConnectionPoints.js"));
60         out.closeEntry();
61         out.putNextEntry(new ZipEntry("javascript/cbam.collectConnectionPoints.js"));
62         out.write(systemFunctions().loadFile("cbam.collectConnectionPoints.js"));
63         out.closeEntry();
64         out.putNextEntry(new ZipEntry("javascript/cbam.post.collectConnectionPoints.js"));
65         out.write(systemFunctions().loadFile("cbam.post.collectConnectionPoints.js"));
66         out.closeEntry();
67         out.close();
68         zipInputStream.close();
69         return result.toByteArray();
70     }
71 }