• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-cli / 1779499080

22 Apr 2025 10:11AM UTC coverage: 1.737% (-30.1%) from 31.802%
1779499080

push

gitlab-ci

web-flow
Merge pull request #277 from alfrunes/MEN-7794

MEN-7794: Add support for pagination when listing devices

28 of 82 new or added lines in 4 files covered. (34.15%)

770 existing lines in 17 files now uncovered.

45 of 2590 relevant lines covered (1.74%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/artifact_upload.go
1
// Copyright 2023 Northern.tech AS
2
//
3
//        Licensed under the Apache License, Version 2.0 (the "License");
4
//        you may not use this file except in compliance with the License.
5
//        You may obtain a copy of the License at
6
//
7
//            http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//        Unless required by applicable law or agreed to in writing, software
10
//        distributed under the License is distributed on an "AS IS" BASIS,
11
//        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//        See the License for the specific language governing permissions and
13
//        limitations under the License.
14
package cmd
15

16
import (
17
        "github.com/pkg/errors"
18

19
        "github.com/spf13/cobra"
20
        "github.com/spf13/viper"
21

22
        "github.com/mendersoftware/mender-cli/client/deployments"
23
        "github.com/mendersoftware/mender-cli/log"
24
)
25

26
const (
27
        argArtifactDescription = "description"
28
        argDirect              = "direct"
29
)
30

31
var artifactUploadCmd = &cobra.Command{
32
        Use:   "upload [flags] ARTIFACT",
33
        Short: "Upload mender artifact to the Mender server.",
34
        Args:  cobra.ExactArgs(1),
UNCOV
35
        Run: func(c *cobra.Command, args []string) {
×
UNCOV
36
                cmd, err := NewArtifactUploadCmd(c, args)
×
UNCOV
37
                CheckErr(err)
×
UNCOV
38
                CheckErr(cmd.Run())
×
UNCOV
39
        },
×
40
}
41

UNCOV
42
func init() {
×
UNCOV
43
        artifactUploadCmd.Flags().StringP(argArtifactDescription, "", "", "artifact description")
×
UNCOV
44
        artifactUploadCmd.Flags().BoolP(argWithoutProgress, "", false, "disable progress bar")
×
UNCOV
45
        artifactUploadCmd.Flags().BoolP(argDirect, "", false, "upload directly to storage")
×
UNCOV
46
}
×
47

48
type ArtifactUploadCmd struct {
49
        server          string
50
        skipVerify      bool
51
        description     string
52
        artifactPath    string
53
        token           string
54
        withoutProgress bool
55
        direct          bool
56
}
57

UNCOV
58
func NewArtifactUploadCmd(cmd *cobra.Command, args []string) (*ArtifactUploadCmd, error) {
×
UNCOV
59
        server := viper.GetString(argRootServer)
×
UNCOV
60
        if server == "" {
×
61
                return nil, errors.New("No server")
×
62
        }
×
63

UNCOV
64
        skipVerify, err := cmd.Flags().GetBool(argRootSkipVerify)
×
UNCOV
65
        if err != nil {
×
66
                return nil, err
×
67
        }
×
68

UNCOV
69
        artifactDescription, err := cmd.Flags().GetString(argArtifactDescription)
×
UNCOV
70
        if err != nil {
×
71
                return nil, err
×
72
        }
×
73

UNCOV
74
        withoutProgress, err := cmd.Flags().GetBool(argWithoutProgress)
×
UNCOV
75
        if err != nil {
×
76
                return nil, err
×
77
        }
×
78

UNCOV
79
        direct, err := cmd.Flags().GetBool(argDirect)
×
UNCOV
80
        if err != nil {
×
81
                return nil, err
×
82
        }
×
83

UNCOV
84
        token, err := getAuthToken(cmd)
×
UNCOV
85
        if err != nil {
×
86
                return nil, err
×
87
        }
×
88

UNCOV
89
        return &ArtifactUploadCmd{
×
UNCOV
90
                server:          server,
×
UNCOV
91
                description:     artifactDescription,
×
UNCOV
92
                token:           token,
×
UNCOV
93
                artifactPath:    args[0],
×
UNCOV
94
                skipVerify:      skipVerify,
×
UNCOV
95
                withoutProgress: withoutProgress,
×
UNCOV
96
                direct:          direct,
×
UNCOV
97
        }, nil
×
98
}
99

UNCOV
100
func (c *ArtifactUploadCmd) Run() error {
×
UNCOV
101
        client := deployments.NewClient(c.server, c.skipVerify)
×
UNCOV
102
        if c.direct {
×
UNCOV
103
                log.Infof("getting direct link.\n")
×
UNCOV
104
                link, err := client.DirectDownloadLink(c.token)
×
UNCOV
105
                if err != nil {
×
106
                        return errors.Wrap(err, "failed to get the direct pre-signed URL")
×
107
                }
×
108

UNCOV
109
                log.Infof("uploading the artifact.\n")
×
UNCOV
110
                err = client.DirectUpload(
×
UNCOV
111
                        c.token,
×
UNCOV
112
                        c.artifactPath,
×
UNCOV
113
                        link.ArtifactID,
×
UNCOV
114
                        link.Uri,
×
UNCOV
115
                        link.Header,
×
UNCOV
116
                        c.withoutProgress,
×
UNCOV
117
                )
×
UNCOV
118
                if err != nil {
×
119
                        return errors.Wrap(err, "failed to upload the artifact")
×
120
                }
×
UNCOV
121
        } else {
×
UNCOV
122
                err := client.UploadArtifact(c.description, c.artifactPath, c.token, c.withoutProgress)
×
UNCOV
123
                if err != nil {
×
124
                        return err
×
125
                }
×
126
        }
127

UNCOV
128
        log.Info("upload successful")
×
UNCOV
129

×
UNCOV
130
        return nil
×
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc