MCPcopy Index your code
hub / github.com/jetify-com/devbox / PullToTmp

Function PullToTmp

internal/pullbox/s3/pull.go:23–76  ·  view source on GitHub ↗
(
	ctx context.Context,
	creds *devopt.Credentials,
	profile string,
)

Source from the content-addressed store, hash-verified

21var ErrProfileNotFound = errors.New("profile not found")
22
23func PullToTmp(
24 ctx context.Context,
25 creds *devopt.Credentials,
26 profile string,
27) (string, error) {
28 config, err := assumeRole(ctx, creds)
29 if err != nil {
30 return "", err
31 }
32
33 // TODO(landau), before pulling, ensure that the profile exists in the cloud
34 s3Client := manager.NewDownloader(s3.NewFromConfig(*config))
35 buf := manager.WriteAtBuffer{}
36
37 ux.Finfof(
38 os.Stderr,
39 "Logged in as %s, pulling from jetify cloud (profile: %s)\n",
40 creds.Email,
41 profile,
42 )
43
44 if _, err = s3Client.Download(
45 ctx,
46 &buf,
47 &s3.GetObjectInput{
48 Bucket: aws.String(bucket),
49 Key: aws.String(
50 fmt.Sprintf(
51 "profiles/%s/%s.tar.gz",
52 creds.Sub,
53 profile,
54 ),
55 ),
56 },
57 // TODO, we can use an s3 list objects to make this more accurate
58 ); err != nil && strings.Contains(err.Error(), "AccessDenied") {
59 return "", ErrProfileNotFound
60 } else if err != nil {
61 return "", errors.WithStack(err)
62 }
63
64 dir, err := tar.Extract(buf.Bytes())
65 if err != nil {
66 return "", err
67 }
68
69 ux.Fsuccessf(
70 os.Stderr,
71 "Profile successfully pulled (profile: %s)\n",
72 profile,
73 )
74
75 return dir, nil
76}

Callers 1

PullMethod · 0.92

Calls 8

FinfofFunction · 0.92
ExtractFunction · 0.92
FsuccessfFunction · 0.92
assumeRoleFunction · 0.85
DownloadMethod · 0.80
BytesMethod · 0.80
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected