com.artipie.helm.metadata.IndexYamlMapping Maven / Gradle / Ivy
The newest version!
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 artipie.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.artipie.helm.metadata;
import com.artipie.asto.Content;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
/**
* Mapping for content from index.yaml file.
* @since 0.2
*/
@SuppressWarnings("unchecked")
public final class IndexYamlMapping {
/**
* Entries.
*/
private static final String ENTRS = "entries";
/**
* Version.
*/
private static final String VRSN = "version";
/**
* Mapping for fields from index.yaml file.
*/
private final Map mapping;
/**
* Ctor.
*/
public IndexYamlMapping() {
this("apiVersion: v1\nentries:\n");
}
/**
* Ctor.
* @param yaml Index.yaml file
*/
public IndexYamlMapping(final String yaml) {
this((Map) new Yaml().load(yaml));
}
/**
* Ctor.
* @param mapfromindex Mapping for fields from index.yaml file
*/
public IndexYamlMapping(final Map mapfromindex) {
this.mapping = mapfromindex;
}
/**
* Obtain mapping for `entries`.
* @return Mapping for `entries`.
*/
public Map entries() {
this.mapping.computeIfAbsent(IndexYamlMapping.ENTRS, k -> new HashMap<>());
return (Map) this.mapping.get(IndexYamlMapping.ENTRS);
}
/**
* Obtain mapping for specified chart from `entries`.
* @param chartname Chart name
* @return Mapping for specified chart from `entries`.
*/
public List