-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathmain.go
More file actions
175 lines (153 loc) · 5.78 KB
/
main.go
File metadata and controls
175 lines (153 loc) · 5.78 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/***************************************************************
*
* Copyright (C) 2024, Pelican Project, Morgridge Institute for Research
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************/
package main
import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/logging"
"github.com/pelicanplatform/pelican/param"
"github.com/pelicanplatform/pelican/server_structs"
"github.com/pelicanplatform/pelican/server_utils"
)
//go:generate go run . generate-docs
func main() {
logging.SetupLogBuffering()
defer logging.FlushLogs(false)
if len(os.Args) > 1 && os.Args[1] == "generate-docs" {
err := generateCLIDocs("docs/app/commands-reference")
if err != nil {
os.Exit(1)
}
return
}
err := handleCLI(os.Args)
if err != nil {
os.Exit(1)
}
}
func handleCLI(args []string) error {
execName := filepath.Base(args[0])
// Take care of our Windows users
execName = strings.TrimSuffix(execName, ".exe")
// Being case-insensitive
execName = strings.ToLower(execName)
if strings.HasPrefix(execName, "stash_plugin") || strings.HasPrefix(execName, "osdf_plugin") || strings.HasPrefix(execName, "pelican_xfer_plugin") || strings.HasPrefix(execName, "pelican_plugin") {
stashPluginMain(args[1:])
} else if strings.HasPrefix(execName, "stashcp") {
err := copyCmd.Execute()
if err != nil {
return err
}
} else {
// * We assume that os.Args should have minimum length of 1, so skipped empty check
// * Version flag is captured manually to ensure it's available to all the commands and subcommands
// This is because there's no gracefully way to do it through Cobra
// * Note that append "--version" to CLI as the last argument will give the
// version info regardless of the commands and whether they are defined
// * Remove the -v shorthand since in "origin serve" flagset it's already used for "volume" flag
if args[len(args)-1] == "--version" {
config.PrintPelicanVersion(os.Stdout)
return nil
}
err := Execute()
if errors.Is(err, server_utils.ErrInvalidOriginConfig) {
mode := param.Origin_StorageType.GetString()
backendType, _ := server_structs.ParseOriginStorageType(mode)
switch backendType {
case server_structs.OriginStoragePosix:
fmt.Fprintf(os.Stderr, `
Export information was not correct.
For POSIX, to specify exports via the command line, use:
-v /mnt/foo:/bar -v /mnt/test:/baz
to export the directories /mnt/foo and /mnt/test under the namespace prefixes /bar and /baz, respectively.
Alternatively, specify Origin.Exports in the parameters.yaml file:
Origin:
Exports:
- StoragePrefix: /mnt/foo
FederationPrefix: /bar
Capabilities: ["PublicReads", "Writes", "Listings"]
- StoragePrefix: /mnt/test
FederationPrefix: /baz
Capabilities: ["Writes"]
to export the directories /mnt/foo and /mnt/test under the namespace prefixes /bar and /baz, respectively (with listed permissions).
`)
case server_structs.OriginStorageS3:
fmt.Fprintf(os.Stderr, `
Export information was not correct.
To specify exports via the command line, use:
-v my-bucket:/my/prefix (REQUIRED --service-url https://my-s3-url.com) (REQUIRED --url-style <path or virtual>) \
(REQUIRED --region "my-region") (OPTIONAL --bucket-access-keyfile /path/to/access.key) \
(OPTIONAL --bucket-secret-keyfile /path/to/secret.key)
to export the S3 bucket under the namespace prefix /my/prefix.
Alternatively, specify Origin.Exports in the parameters.yaml file:
Origin:
StorageType: s3
S3UrlStyle: <path or virtual>
S3ServiceUrl: https://my-s3-url.com
S3Region: my-region
Exports:
- FederationPrefix: /my/prefix
S3Bucket: my-bucket
S3AccessKeyfile: /path/to/access.key
S3SecretKeyfile: /path/to/secret.key
Capabilities: ["PublicReads", "Writes", "Listings"]
to export the S3 bucket my-bucket from https://my-s3-url.com under the namespace prefix /my/prefix (with listed permissions).
`)
case server_structs.OriginStorageHTTPS:
fmt.Fprintf(os.Stderr, `
Export information was not correct.
HTTPS exports must be specified via configuration file. Example:
Origin:
StorageType: https
FederationPrefix: /my/prefix
HttpServiceUrl: "https://example.com/testfiles"
Capabilities: ["PublicReads", "Writes", "Listings"]
`)
case server_structs.OriginStorageXRoot:
fmt.Fprintf(os.Stderr, `
Export information was not correct.
For xroot backends, specify exports via the command line using the -v flag. Example:
-v /foo:/foo -v /bar:/bar (REQUIRED --xroot-service-url upstream-xroot-url.com:1095)
Note that this backend type requires that the Storage Prefix (before the colon) and Federation Prefix (after the colon) match.
It also requires that the exports are configured for public reads.
Alternatively, specify Origin.Exports in the parameters.yaml file:
Origin:
StorageType: xroot
XRootServiceUrl: upstream-xroot-url.com:1095
Exports:
- StoragePrefix: /foo
FederationPrefix: /
Capabilities: ["PublicReads", "Writes", "Listings"]
- StoragePrefix: /bar
FederationPrefix: /bar
Capabilities: ["PublicReads", "Writes"]
`)
default:
fmt.Fprintf(os.Stderr, "Currently-supported origin modes include posix, https, and s3, but you provided %s.", mode)
}
}
if err != nil {
os.Exit(1)
}
}
return nil
}