Add device capability and get authenticated device list
[platform/core/system/edge-orchestration.git] / patches / utils.patch
1 diff --git a/src/common/utils/utils.go b/src/common/utils/utils.go
2 new file mode 100644
3 index 0000000..24098bd
4 --- /dev/null
5 +++ b/src/common/utils/utils.go
6 @@ -0,0 +1,63 @@
7 +/*******************************************************************************
8 + * Copyright 2020 Samsung Electronics All Rights Reserved.
9 + *
10 + * Licensed under the Apache License, Version 2.0 (the "License");
11 + * you may not use this file except in compliance with the License.
12 + * You may obtain a copy of the License at
13 + *
14 + * http://www.apache.org/licenses/LICENSE-2.0
15 + *
16 + * Unless required by applicable law or agreed to in writing, software
17 + * distributed under the License is distributed on an "AS IS" BASIS,
18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 + * See the License for the specific language governing permissions and
20 + * limitations under the License.
21 + *
22 + *******************************************************************************/
23 +
24 +// Package utils helps us keep utility functions like ping for common usage
25 +package utils
26 +
27 +import (
28 +       "log"
29 +       "restinterface/resthelper"
30 +)
31 +
32 +const (
33 +       pingAPI      = "/api/v1/ping"
34 +       internalPort = 56002
35 +       logPrefix    = "[utils]"
36 +)
37 +
38 +var (
39 +       logTag = logPrefix + "[Ping]"
40 +       helper resthelper.RestHelper
41 +       util   *utilsImpl
42 +)
43 +
44 +func init() {
45 +       util = new(utilsImpl)
46 +       helper = resthelper.GetHelper()
47 +}
48 +
49 +type utilsImpl struct{}
50 +
51 +type UtilsHelper interface {
52 +       PingDevice(ip string) bool
53 +}
54 +
55 +// GetHelper returns utilImpl instance
56 +func GetHelper() UtilsHelper {
57 +       return util
58 +}
59 +
60 +func (ut *utilsImpl) PingDevice(ip string) bool {
61 +       targetURL := helper.MakeTargetURL(ip, internalPort, pingAPI)
62 +       _, _, err := helper.DoGet(targetURL)
63 +       if err != nil {
64 +               log.Println(logTag, "PING Error:", err.Error())
65 +               return false
66 +       }
67 +
68 +       return true
69 +}