/
registry.go
146 lines (124 loc) · 4.34 KB
/
registry.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// 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) 2019-2023, Sylabs Inc. All rights reserved.
// Copyright (c) 2020, Control Command 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 cli
import (
"github.com/apptainer/apptainer/docs"
"github.com/apptainer/apptainer/internal/app/apptainer"
"github.com/apptainer/apptainer/pkg/cmdline"
"github.com/apptainer/apptainer/pkg/sylog"
"github.com/spf13/cobra"
)
// -c|--config
var registryConfigFlag = cmdline.Flag{
ID: "registryConfigFlag",
Value: &remoteConfig,
DefaultValue: remoteConfigUser,
Name: "config",
ShortHand: "c",
Usage: "path to the file holding registry configurations",
}
// -u|--username
var registryLoginUsernameFlag = cmdline.Flag{
ID: "registryLoginUsernameFlag",
Value: &loginUsername,
DefaultValue: "",
Name: "username",
ShortHand: "u",
Usage: "username to authenticate with (required for Docker/OCI registry login)",
EnvKeys: []string{"LOGIN_USERNAME"},
}
// -p|--password
var registryLoginPasswordFlag = cmdline.Flag{
ID: "registryLoginPasswordFlag",
Value: &loginPassword,
DefaultValue: "",
Name: "password",
ShortHand: "p",
Usage: "password / token to authenticate with",
EnvKeys: []string{"LOGIN_PASSWORD"},
}
// --password-stdin
var registryLoginPasswordStdinFlag = cmdline.Flag{
ID: "registryLoginPasswordStdinFlag",
Value: &loginPasswordStdin,
DefaultValue: false,
Name: "password-stdin",
Usage: "take password from standard input",
}
func init() {
addCmdInit(func(cmdManager *cmdline.CommandManager) {
cmdManager.RegisterCmd(RegistryCmd)
cmdManager.RegisterSubCmd(RegistryCmd, RegistryLoginCmd)
cmdManager.RegisterSubCmd(RegistryCmd, RegistryLogoutCmd)
cmdManager.RegisterSubCmd(RegistryCmd, RegistryListCmd)
// default location of the remote.yaml file is the user directory
cmdManager.RegisterFlagForCmd(®istryConfigFlag, RegistryCmd)
cmdManager.RegisterFlagForCmd(®istryLoginUsernameFlag, RegistryLoginCmd)
cmdManager.RegisterFlagForCmd(®istryLoginPasswordFlag, RegistryLoginCmd)
cmdManager.RegisterFlagForCmd(®istryLoginPasswordStdinFlag, RegistryLoginCmd)
})
}
// RegistryCmd apptainer registry [...]
var RegistryCmd = &cobra.Command{
Run: nil,
Use: docs.RegistryUse,
Short: docs.RegistryShort,
Long: docs.RegistryLong,
Example: docs.RegistryExample,
DisableFlagsInUseLine: true,
}
// RegistryLoginCmd apptainer registry login [option] <registry_url>
var RegistryLoginCmd = &cobra.Command{
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.RegistryLogin(remoteConfig, ObtainLoginArgs(args[0])); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.RegistryLoginUse,
Short: docs.RegistryLoginShort,
Long: docs.RegistryLoginLong,
Example: docs.RegistryLoginExample,
DisableFlagsInUseLine: true,
}
// RegistryLogoutCmd apptainer remote logout [remoteName|serviceURI]
var RegistryLogoutCmd = &cobra.Command{
Args: cobra.RangeArgs(0, 1),
Run: func(cmd *cobra.Command, args []string) {
// default to empty string to signal to registryLogin to use default remote
name := ""
if len(args) > 0 {
name = args[0]
}
if err := apptainer.RegistryLogout(remoteConfig, name); err != nil {
sylog.Fatalf("%s", err)
}
sylog.Infof("Logout succeeded")
},
Use: docs.RegistryLogoutUse,
Short: docs.RegistryLogoutShort,
Long: docs.RegistryLogoutLong,
Example: docs.RegistryLogoutExample,
DisableFlagsInUseLine: true,
}
// RegistryListCmd apptainer remote list
var RegistryListCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
if err := apptainer.RegistryList(remoteConfig); err != nil {
sylog.Fatalf("%s", err)
}
},
Use: docs.RegistryListUse,
Short: docs.RegistryListShort,
Long: docs.RegistryListLong,
Example: docs.RegistryListExample,
DisableFlagsInUseLine: true,
}