Skip to content

Commit

Permalink
Remove unused code (#437)
Browse files Browse the repository at this point in the history
Signed-off-by: Taras Drozdovskyi <[email protected]>
  • Loading branch information
tdrozdovsky authored Dec 13, 2021
1 parent c65b5e1 commit 86d083d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 92 deletions.
21 changes: 0 additions & 21 deletions cmd/edge-orchestration/capi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static char* bridge_kGetter(char* id){
*/
import "C"
import (
"errors"
"flag"
"math"
"strings"
Expand Down Expand Up @@ -307,26 +306,6 @@ func OrchestrationRequestService(cAppName *C.char, cSelfSelection C.int, cReques

type customHandler struct{}

func (cHandler customHandler) GetIdentity() string {
var cIdentity *C.char
cIdentity = C.bridge_iGetter()
identity := C.GoString(cIdentity)
return identity
}

func (cHandler customHandler) GetKey(id string) ([]byte, error) {
var cKey *C.char
cStr := C.CString(id)
defer C.free(unsafe.Pointer(cStr))

cKey = C.bridge_kGetter(cStr)
key := C.GoString(cKey)
if len(key) == 0 {
return nil, errors.New("key is empty")
}
return []byte(key), nil
}

// SetHandler sets handler
//export SetHandler
func SetHandler(iGetter C.identityGetterFunc, kGetter C.keyGetterFunc) {
Expand Down
29 changes: 1 addition & 28 deletions internal/restinterface/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
package tls

import (
"io/ioutil"
"sync/atomic"

"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr"
"github.com/satori/go.uuid"
)

// File names of certificate and private key
Expand Down Expand Up @@ -54,10 +52,7 @@ func GetCertFilePath() string {
}

// Handler provides interfaces for the tls
type Handler interface {
GetIdentity() string
GetKey(identity string) ([]byte, error)
}
type Handler interface{}

// CertificateSetter interface provides setting the certificate file path
type CertificateSetter interface {
Expand Down Expand Up @@ -92,26 +87,4 @@ func (h *HasCertificate) GetCertificateFilePath() string {
return ""
}

// GetIdentity gets identity
func GetIdentity() string {
return handler.GetIdentity()
}

// GetKey gets key using id
func GetKey(id string) ([]byte, error) {
return handler.GetKey(id)
}

type defaultIdentifier struct{}

func (defaultIdentifier) GetIdentity() string {
return uuid.Must(uuid.NewV4(), nil).String()
}

func (defaultIdentifier) GetKey(id string) ([]byte, error) {
key, err := ioutil.ReadFile(GetCertFilePath() + "/" + KeyFileName)
if err != nil {
return nil, err
}
return key, nil
}
42 changes: 0 additions & 42 deletions internal/restinterface/tls/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package tls

import (
"os"
"testing"
)

Expand Down Expand Up @@ -53,44 +52,3 @@ func TestHasCertificate(t *testing.T) {
t.Error("unexpected value: ")
}
}

func TestGetIdentity(t *testing.T) {
if GetIdentity() == GetIdentity() {
t.Error("expect different value, but it is same")
}
}

func TestGetKey(t *testing.T) {
testKeyName := "edge-orchestration.key"
testPath := "./"
testStr := "this is test"
SetCertFilePath(testPath)

t.Run("Error", func(t *testing.T) {
_, err := GetKey("")
if err == nil {
t.Error("unexpected succeed")
}
})
t.Run("Success", func(t *testing.T) {
f, err := os.Create(testPath + testKeyName)
if err != nil {
t.Error(err.Error())
}
defer func() {
f.Close()
os.Remove(testPath + testKeyName)
}()

f.Write([]byte(testStr))

ret, err := GetKey("")
if err != nil {
t.Error(err.Error())
}
if string(ret) != testStr {
t.Error("unexpeted value: ", string(ret))
}
})

}
2 changes: 1 addition & 1 deletion staticcheck.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
checks = ["all", "-ST1000", "-ST1016", "-U1000", "-S1000",
"-S1021", "-S1034", "-S1040", "-SA4000"]
"-S1021", "-S1034", "-S1040"]
initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS",
"EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID",
"IP", "JSON", "QPS", "RAM", "RPC", "SLA",
Expand Down

0 comments on commit 86d083d

Please sign in to comment.