-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new command to create deployments. Signed-off-by: Lars Rustand <[email protected]>
- Loading branch information
Showing
4 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2023 Northern.tech AS | ||
// | ||
// 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 cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/mendersoftware/mender-cli/client/deployments" | ||
"github.com/mendersoftware/mender-cli/log" | ||
) | ||
|
||
const ( | ||
argDeploymentName = "deployment-name" | ||
) | ||
|
||
var deploymentCreateCmd = &cobra.Command{ | ||
Use: "create [flags] DEPLOYMENT_NAME ARTIFACT_NAME DEVICE_LIST", | ||
Short: "Create a new deployment from an existing artifact on the Mender server.", | ||
Run: func(c *cobra.Command, args []string) { | ||
cmd, err := CreateDeploymentCmd(c, args) | ||
CheckErr(err) | ||
CheckErr(cmd.Run()) | ||
}, | ||
} | ||
|
||
func init() { | ||
deploymentCreateCmd.Flags().StringP(argDeploymentName, "", "", | ||
"destination path to download to") | ||
} | ||
|
||
type DeploymentCreateCmd struct { | ||
server string | ||
deploymentName string | ||
artifactID string | ||
deviceList string | ||
token string | ||
} | ||
|
||
func CreateDeploymentCmd(cmd *cobra.Command, args []string) (*DeploymentCreateCmd, error) { | ||
server := viper.GetString(argRootServer) | ||
if server == "" { | ||
return nil, errors.New("No server") | ||
} | ||
|
||
deploymentName = "" | ||
if len(args) > 1 { | ||
deploymentName = args[0] | ||
} | ||
|
||
artifactID := "" | ||
if len(args) > 2 { | ||
artifactID = args[1] | ||
} | ||
|
||
deviceList := "" | ||
if len(args) >= 3 { | ||
deviceList = args[2] | ||
} | ||
|
||
token, err := getAuthToken(cmd) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &DeploymentCreateCmd{ | ||
server: server, | ||
deploymentName: deploymentName, | ||
artifactID: artifactID, | ||
deviceList: deviceList, | ||
token: token, | ||
}, nil | ||
} | ||
|
||
func (c *DeploymentCreateCmd) Run() error { | ||
client := deployments.NewClient(c.server, false) | ||
err := client.CreateDeployment(c.deploymentName, c.artifactID, c.deviceList, c.token) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Info("deployment created succesfully") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2023 Northern.tech AS | ||
// | ||
// 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 cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deploymentsCmd = &cobra.Command{ | ||
Use: "deployments", | ||
Short: "Operations on mender deployments.", | ||
ValidArgs: []string{"create"}, | ||
} | ||
|
||
func init() { | ||
deploymentsCmd.AddCommand(deploymentCreateCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters