2e073a431a64f9c1bc7894e0430df33435044b3f
[sdc.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation
4  *  Modification Copyright (C) 2021 Nokia.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.tosca.csar;
22
23 import java.util.Arrays;
24 import java.util.Optional;
25
26 public enum ManifestTokenType {
27     ALGORITHM("Algorithm"),
28     ATTRIBUTE_VALUE_SEPARATOR(":"),
29     CMS_BEGIN("-----BEGIN CMS-----"),
30     CMS_END("-----END CMS-----"),
31     HASH("Hash"),
32     METADATA("metadata"),
33     NON_MANO_ARTIFACT_SETS("non_mano_artifact_sets"),
34     SOURCE("Source"),
35     VNF_PRODUCT_NAME("vnf_product_name"),
36     VNF_PROVIDER_ID("vnf_provider_id"),
37     VNF_PACKAGE_VERSION("vnf_package_version"),
38     VNF_RELEASE_DATE_TIME("vnf_release_date_time"),
39     PNFD_NAME("pnfd_name"),
40     PNFD_PROVIDER("pnfd_provider"),
41     PNFD_ARCHIVE_VERSION("pnfd_archive_version"),
42     PNFD_RELEASE_DATE_TIME("pnfd_release_date_time"),
43     SIGNATURE("Signature"),
44     CERTIFICATE("Certificate");
45
46     private final String token;
47
48     ManifestTokenType(final String token) {
49         this.token = token;
50     }
51
52     public String getToken() {
53         return token;
54     }
55
56     public static Optional<ManifestTokenType> parse(final String token) {
57         return Arrays.stream(values()).filter(it -> it.getToken() != null && it.getToken().equals(token)).findFirst();
58     }
59
60     public boolean isMetadataEntry() {
61         return isMetadataVnfEntry() || isMetadataPnfEntry();
62     }
63
64     public boolean isMetadataVnfEntry() {
65         switch (this) {
66             case VNF_PRODUCT_NAME:
67             case VNF_PROVIDER_ID:
68             case VNF_PACKAGE_VERSION:
69             case VNF_RELEASE_DATE_TIME:
70                 return true;
71             default:
72                 return false;
73         }
74     }
75
76     public boolean isMetadataPnfEntry() {
77         switch (this) {
78             case PNFD_NAME:
79             case PNFD_PROVIDER:
80             case PNFD_ARCHIVE_VERSION:
81             case PNFD_RELEASE_DATE_TIME:
82                 return true;
83             default:
84                 return false;
85         }
86     }
87 }