File: metadata.go

package info (click to toggle)
apptainer 1.4.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,780 kB
  • sloc: sh: 3,329; ansic: 1,706; awk: 414; python: 103; makefile: 54
file content (65 lines) | stat: -rw-r--r-- 2,513 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) Contributors to the Apptainer project, established as
//   Apptainer a Series of LF Projects LLC.
//   For website terms of use, trademark policy, privacy policy and other
//   project policies see https://lfprojects.org/policies
// Copyright (c) 2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.

package inspect

// ContainerType defines the container type (used by default).
const ContainerType = "container"

// AppAttributes describes app metadata attributes.
type AppAttributes struct {
	Environment map[string]string `json:"environment,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Runscript   string            `json:"runscript,omitempty"`
	Startscript string            `json:"startscript,omitempty"`
	Test        string            `json:"test,omitempty"`
	Helpfile    string            `json:"helpfile,omitempty"`
}

// Attributes describes metadata attributes of Apptainer containers.
type Attributes struct {
	Apps        map[string]*AppAttributes `json:"apps,omitempty"`
	Environment map[string]string         `json:"environment,omitempty"`
	Labels      map[string]string         `json:"labels,omitempty"`
	Runscript   string                    `json:"runscript,omitempty"`
	Test        string                    `json:"test,omitempty"`
	Helpfile    string                    `json:"helpfile,omitempty"`
	Deffile     string                    `json:"deffile,omitempty"`
	Startscript string                    `json:"startscript,omitempty"`
}

// Data holds the container metadata attributes.
type Data struct {
	Attributes Attributes `json:"attributes"`
}

// Metadata describes the JSON format of Apptainer container metadata.
type Metadata struct {
	Data `json:"data"`
	Type string `json:"type"`
}

func (m *Metadata) AddApp(name string) {
	if _, ok := m.Attributes.Apps[name]; !ok {
		attr := &AppAttributes{}
		attr.Environment = make(map[string]string)
		attr.Labels = make(map[string]string)
		m.Attributes.Apps[name] = attr
	}
}

// NewMetadata returns an initialized instances of Metadata.
func NewMetadata() *Metadata {
	format := new(Metadata)
	format.Type = ContainerType
	format.Attributes.Labels = make(map[string]string)
	format.Attributes.Environment = make(map[string]string)
	format.Attributes.Apps = make(map[string]*AppAttributes)
	return format
}