Skip to content

Commit dce40ed

Browse files
committed
Started work on template apply
1 parent 23be56e commit dce40ed

File tree

5 files changed

+118
-2
lines changed

5 files changed

+118
-2
lines changed

cli/template/apply.go

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// This file is part of arduino-cloud-cli.
2+
//
3+
// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
package template
19+
20+
import (
21+
"fmt"
22+
"os"
23+
24+
"github.com/arduino/arduino-cli/cli/errorcodes"
25+
"github.com/arduino/arduino-cli/cli/feedback"
26+
"github.com/arduino/arduino-cloud-cli/command/template"
27+
"github.com/arduino/arduino-cloud-cli/config"
28+
"github.com/spf13/cobra"
29+
)
30+
31+
type applyFlags struct {
32+
templateId string
33+
templateName string
34+
}
35+
36+
func initTemplateApplyCommand() *cobra.Command {
37+
flags := &applyFlags{}
38+
applyCommand := &cobra.Command{
39+
Use: "apply",
40+
Short: "Apply custom template",
41+
Long: "Given a template, apply it and create all the resources defined in it",
42+
Run: func(cmd *cobra.Command, args []string) {
43+
if err := runTemplateApplyCommand(flags); err != nil {
44+
feedback.Errorf("Error during template apply: %v", err)
45+
os.Exit(errorcodes.ErrGeneric)
46+
}
47+
},
48+
}
49+
50+
applyCommand.Flags().StringVarP(&flags.templateId, "template-id", "t", "", "Template id")
51+
applyCommand.Flags().StringVarP(&flags.templateName, "name", "n", "", "Name")
52+
53+
applyCommand.MarkFlagRequired("template-id")
54+
applyCommand.MarkFlagRequired("name")
55+
56+
return applyCommand
57+
}
58+
59+
func runTemplateApplyCommand(flags *applyFlags) error {
60+
cred, err := config.RetrieveCredentials()
61+
if err != nil {
62+
return fmt.Errorf("retrieving credentials: %w", err)
63+
}
64+
return template.ApplyCustomTemplates(cred, flags.templateId)
65+
}
66+
67+
/*
68+
69+
curl --location --request PUT 'http://localhost:9000/iot/v1/templates' \
70+
--header 'Accept: application/yaml' \
71+
--header 'Content-Type: application/json' \
72+
--header 'Authorization: ' \
73+
--data '{
74+
"template_name": "home",
75+
"custom_template_id": "d864f20e-dcf4-4c8a-b3e7-f1bfffe86f60",
76+
"things_options": {
77+
"home-3a06e": {
78+
"device_id": "08d75172-335e-4cb9-b401-83eb4db213fb",
79+
"secrets": {
80+
"SECRET_SSID": "asdas",
81+
"SECRET_OPTIONAL_PASS": "asdsad"
82+
}
83+
}
84+
}
85+
}'
86+
87+
*/

cli/template/export.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
type exportFlags struct {
3232
templateId string
33-
path string
33+
path string
3434
}
3535

3636
func initTemplateExportCommand() *cobra.Command {

cli/template/template.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NewCommand() *cobra.Command {
3131
templateCommand.AddCommand(initTemplateImportCommand())
3232
templateCommand.AddCommand(initTemplateExportCommand())
3333
templateCommand.AddCommand(initTemplateListCommand())
34+
templateCommand.AddCommand(initTemplateApplyCommand())
3435

3536
return templateCommand
3637
}

command/template/apply.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is part of arduino-cloud-cli.
2+
//
3+
// Copyright (C) 2021 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
package template
19+
20+
import (
21+
"github.com/arduino/arduino-cloud-cli/config"
22+
)
23+
24+
func ApplyCustomTemplates(cred *config.Credentials, templateId string) error {
25+
26+
// TODO
27+
28+
return nil
29+
}

command/template/list.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ func ListCustomTemplates(cred *config.Credentials) error {
3838
feedback.PrintResult(templates)
3939
}
4040

41-
4241
return nil
4342
}

0 commit comments

Comments
 (0)