Added Create and Delete CLI Commands
[ealt-edge.git] / ocd / cli / ealt / cmd / adapter / converter.go
1 /*
2 Copyright 2020 Huawei Technologies Co., Ltd.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8     http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package adapter
18
19 import (
20         "ealt/cmd/common"
21         "encoding/json"
22         "fmt"
23         "log"
24         "strings"
25 )
26
27 func BuilderRequest(valueArgs []string, command string) error {
28
29         var URIString string
30
31         switch command {
32         case "NewAppCreateCommand":
33                 //Onboard Command
34                 //ealtedge/mepm/app_pkgm/v1/app_packages/
35                 //read the file from the system.
36                 URIString = common.AppmUri
37                 var packageName string
38                 var body []byte
39                 body = jsonEmptyBodyFormat()
40                 packageName = strings.TrimSpace(valueArgs[0])
41                 HttpMultiPartPostRequestBuilder(URIString, body, packageName)
42                 fmt.Println(packageName)
43
44         case "NewAppDeleteCommand":
45                 //The Delete Application Package URI
46                 //ealtedge/mepm/app_pkgm/v1/app_packages/{{ID}}
47                 var body []byte
48                 URIString = common.AppmUri + strings.TrimSpace(valueArgs[0])
49                 body = jsonEmptyBodyFormat()
50                 fmt.Println(URIString)
51                 HttpDeleteRequestBuilder(URIString, body)
52
53                 fmt.Println(URIString)
54
55         case "NewApplcmCreateCommand":
56                 //appLCM application Creation URI
57                 //ealtedge/mepm/app_lcm/v1/app_instances
58                 var body []byte
59
60                 URIString = common.ApplcmUri
61                 body, err := json.Marshal(map[string]string{
62                         "appDId":                strings.TrimSpace(valueArgs[0]),
63                         "appInstancename":       strings.TrimSpace(valueArgs[1]),
64                         "appInstanceDescriptor": strings.TrimSpace(valueArgs[2]),
65                 })
66
67                 if err != nil {
68                         log.Fatalln(err)
69                 }
70                 fmt.Println(URIString)
71                 HttpPostRequestBuilder(URIString, body)
72
73         case "NewApplcmDeleteCommand":
74                 //appLCM Delete Application URI
75                 ///ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}
76                 var body []byte
77                 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0])
78                 body = jsonEmptyBodyFormat()
79                 fmt.Println(URIString)
80                 HttpDeleteRequestBuilder(URIString, body)
81
82         case "NewApplcmStartCommand":
83                 //applcm application instantiate uri
84                 //ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/instantiate
85                 var body []byte
86
87                 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0]) + common.InstantiateUri
88                 body = jsonEmptyBodyFormat()
89                 fmt.Println(URIString)
90                 HttpPostRequestBuilder(URIString, body)
91
92         case "NewApplcmTerminateCommand":
93                 //applcm application terminate uri
94                 //ealtedge/mepm/app_lcm/v1/app_instances/{appInstanceId}/terminate
95                 var body []byte
96                 URIString = common.ApplcmUri + strings.TrimSpace(valueArgs[0]) + common.TerminateUri
97                 body = jsonEmptyBodyFormat()
98                 fmt.Println(URIString)
99                 HttpPostRequestBuilder(URIString, body)
100
101         }
102
103         return nil
104 }
105
106 func jsonEmptyBodyFormat() []byte {
107         var jsonstr []byte
108         jsonstr = []byte(`{"":""}`)
109         return jsonstr
110 }