-
Notifications
You must be signed in to change notification settings - Fork 187
/
config.go
51 lines (42 loc) · 1.09 KB
/
config.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
// Copyright 2024 Jetify Inc. and contributors. All rights reserved.
// Use of this source code is governed by the license in the LICENSE file.
package pullbox
import (
"context"
"net/url"
"os"
"path/filepath"
"go.jetpack.io/devbox/internal/cuecfg"
"go.jetpack.io/devbox/internal/devconfig"
"go.jetpack.io/devbox/internal/fileutil"
)
func (p *pullbox) IsTextDevboxConfig() bool {
if u, err := url.Parse(p.URL); err == nil {
ext := filepath.Ext(u.Path)
return cuecfg.IsSupportedExtension(ext)
}
// For invalid URLS, just look at the extension
ext := filepath.Ext(p.URL)
return cuecfg.IsSupportedExtension(ext)
}
func (p *pullbox) pullTextDevboxConfig(ctx context.Context) error {
if p.isLocalConfig() {
return p.copyToProfile(p.URL)
}
cfg, err := devconfig.LoadConfigFromURL(ctx, p.URL)
if err != nil {
return err
}
tmpDir, err := fileutil.CreateDevboxTempDir()
if err != nil {
return err
}
if err = cfg.Root.SaveTo(tmpDir); err != nil {
return err
}
return p.copyToProfile(tmpDir)
}
func (p *pullbox) isLocalConfig() bool {
_, err := os.Stat(p.URL)
return err == nil
}