Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CloudSyncMgr] Renaming the CloudSyncMgr API according to functionality to add more APIs #483

Merged
merged 6 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cloudsync_mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ docker run -it -d --privileged --network="host" --name edge-orchestration -e CLO
From the another terminal/post make a curl command as follows to publish data using home edge to the broker running on AWS endpoint

```
curl --location --request POST 'http://<ip where edgeorchestration is running>:56001/api/v1/orchestration/cloudsyncmgr' \
curl --location --request POST 'http://<ip where edgeorchestration is running>:56001/api/v1/orchestration/cloudsyncmgr/publish' \
--header 'Content-Type: text/plain' \
--data-raw '{
"appid": "<appid of service app>",
Expand Down
4 changes: 2 additions & 2 deletions docs/secure_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ The system is currently configured in the simplest configuration with two roles:
| ---------------------------------- | ----- | ------ |
| /api/v1/orchestration/services | Allow | Allow |
| /api/v1/orchestration/securemgr | Allow | Deny |
| /api/v1/orchestration/cloudsyncmgr | Allow | Allow |
| /api/v1/orchestration/cloudsyncmgr/publish | Allow | Allow |

To change the access model and policy, you need to edit the files:
`/var/edge-orchestration/data/rbac/auth_model.conf`
Expand All @@ -245,7 +245,7 @@ and `/var/edge-orchestration/data/rbac/policy.csv`
```
p, admin, /*, *
p, member, /api/v1/orchestration/services, *
p, member, /api/v1/orchestration/cloudsyncmgr, *
p, member, /api/v1/orchestration/cloudsyncmgr/publish, *
```
---

Expand Down
6 changes: 3 additions & 3 deletions internal/controller/cloudsyncmgr/cloudsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
type CloudSync interface {
InitiateCloudSync(isCloudSet string) error
//implemented by external REST API
RequestCloudSyncConf(host string, clientID string, message mqttmgr.Message, topic string) string
RequestPublish(host string, clientID string, message mqttmgr.Message, topic string) string
}

//CloudSyncImpl struct
Expand Down Expand Up @@ -81,8 +81,8 @@ func (c *CloudSyncImpl) InitiateCloudSync(isCloudSet string) (err error) {
return nil
}

// RequestCloudSyncConf is configuration request handler
func (c *CloudSyncImpl) RequestCloudSyncConf(host string, clientID string, message mqttmgr.Message, topic string) string {
// RequestPublish is configuration request handler
func (c *CloudSyncImpl) RequestPublish(host string, clientID string, message mqttmgr.Message, topic string) string {
log.Info(logPrefix, "Publishing the data to the cloud")
resp := ""
var wg sync.WaitGroup
Expand Down
12 changes: 6 additions & 6 deletions internal/controller/cloudsyncmgr/mocks/mocks_cloudsync.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/securemgr/authorizer/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
rbacPolicyFileName = "policy.csv"
policyTemplate = "p, admin, /*, *\n" +
"p, member, /api/v1/orchestration/services, *\n" +
"p, member, /api/v1/orchestration/cloudsyncmgr, *\n"
"p, member, /api/v1/orchestration/cloudsyncmgr/publish, *\n"
rbacAuthModelFileName = "auth_model.conf"
authModelTemplate = "[request_definition]\n" +
"r = sub, obj, act\n\n" +
Expand Down
12 changes: 6 additions & 6 deletions internal/orchestrationapi/mocks/mock_orchestration.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/orchestrationapi/orchestration.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Orche interface {
type OrcheExternalAPI interface {
RequestService(serviceInfo ReqeustService) ResponseService
verifier.Conf
RequestCloudSync(host string, clientID string, message mqtt.Message, topic string) string
RequestCloudSyncPublish(host string, clientID string, message mqtt.Message, topic string) string
}

// OrcheInternalAPI is the interface implemented by internal REST API
Expand Down
8 changes: 4 additions & 4 deletions internal/orchestrationapi/orchestrationapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func init() {
helper = dbhelper.GetInstance()
}

//RequestCloudSync handles the request for cloud syncing
func (orcheEngine *orcheImpl) RequestCloudSync(host string, clientID string, message mqtt.Message, topic string) string {
log.Info("[RequestCloudSync]", "Requesting cloud sync")
return orcheEngine.cloudsyncIns.RequestCloudSyncConf(host, clientID, message, topic)
//RequestCloudSyncPublish handles the request for cloud syncing
func (orcheEngine *orcheImpl) RequestCloudSyncPublish(host string, clientID string, message mqtt.Message, topic string) string {
log.Info("[RequestCloudSync]", "Requesting cloud sync publish")
return orcheEngine.cloudsyncIns.RequestPublish(host, clientID, message, topic)
}

// RequestService handles service request (ex. offloading) from service application
Expand Down
14 changes: 7 additions & 7 deletions internal/restinterface/externalhandler/externalhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func init() {
HandlerFunc: handler.APIV1RequestSecuremgrPost,
},
restinterface.Route{
Name: "APIV1RequestCloudSyncmgrPost",
Name: "APIV1RequestCloudSyncmgrPublish",
Method: strings.ToUpper("Post"),
Pattern: "/api/v1/orchestration/cloudsyncmgr",
HandlerFunc: handler.APIV1RequestCloudSyncmgrPost,
Pattern: "/api/v1/orchestration/cloudsyncmgr/publish",
HandlerFunc: handler.APIV1RequestCloudSyncmgrPublish,
},
}
handler.netHelper = networkhelper.GetInstance()
Expand Down Expand Up @@ -374,9 +374,9 @@ SEND_RESP:
h.helper.Response(w, respEncryptBytes, http.StatusOK)
}

// APIV1RequestCloudSyncmgrPost handles cloudsync publish request from service application
func (h *Handler) APIV1RequestCloudSyncmgrPost(w http.ResponseWriter, r *http.Request) {
log.Info(logPrefix, "APIV1RequestCloudSyncmgrPost")
// APIV1RequestCloudSyncmgrPublish handles cloudsync publish request from service application
func (h *Handler) APIV1RequestCloudSyncmgrPublish(w http.ResponseWriter, r *http.Request) {
log.Info(logPrefix, "APIV1RequestCloudSyncmgrPublish")
if !h.isSetAPI {
log.Error(logPrefix, doesNotSetAPI)
h.helper.Response(w, nil, http.StatusServiceUnavailable)
Expand Down Expand Up @@ -448,7 +448,7 @@ func (h *Handler) APIV1RequestCloudSyncmgrPost(w http.ResponseWriter, r *http.Re
goto SEND_RESP
}

responseMsg = h.api.RequestCloudSync(host, appID, publishMessage, topic)
responseMsg = h.api.RequestCloudSyncPublish(host, appID, publishMessage, topic)

SEND_RESP:
respJSONMsg := make(map[string]interface{})
Expand Down
14 changes: 7 additions & 7 deletions internal/restinterface/externalhandler/externalhandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func TestAPIV1RequestServicePost(t *testing.T) {
})
}

func TestAPIV1RequestCloudSyncmgrPost(t *testing.T) {
func TestAPIV1RequestCloudSyncmgrPublish(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -314,15 +314,15 @@ func TestAPIV1RequestCloudSyncmgrPost(t *testing.T) {
mockHelper.EXPECT().Response(gomock.Any(), gomock.Any(), gomock.Eq(http.StatusServiceUnavailable))

handler.isSetAPI = false
handler.APIV1RequestCloudSyncmgrPost(w, r)
handler.APIV1RequestCloudSyncmgrPublish(w, r)
})
t.Run("IsNotSetKey", func(t *testing.T) {
handler.SetOrchestrationAPI(mockOrchestration)
handler.setHelper(mockHelper)
mockHelper.EXPECT().Response(gomock.Any(), gomock.Any(), gomock.Eq(http.StatusServiceUnavailable))

handler.IsSetKey = false
handler.APIV1RequestCloudSyncmgrPost(w, r)
handler.APIV1RequestCloudSyncmgrPublish(w, r)
})
t.Run("DecryptionFail", func(t *testing.T) {
handler.SetCipher(mockCipher)
Expand All @@ -335,7 +335,7 @@ func TestAPIV1RequestCloudSyncmgrPost(t *testing.T) {
mockHelper.EXPECT().Response(gomock.Any(), gomock.Any(), gomock.Eq(http.StatusServiceUnavailable)),
)

handler.APIV1RequestCloudSyncmgrPost(w, r)
handler.APIV1RequestCloudSyncmgrPublish(w, r)
})
t.Run("InvalidParam", func(t *testing.T) {
t.Run("ServiceName", func(t *testing.T) {
Expand All @@ -358,7 +358,7 @@ func TestAPIV1RequestCloudSyncmgrPost(t *testing.T) {
mockHelper.EXPECT().Response(gomock.Any(), gomock.Any(), gomock.Eq(http.StatusOK)),
)

handler.APIV1RequestCloudSyncmgrPost(w, r)
handler.APIV1RequestCloudSyncmgrPublish(w, r)
})
t.Run("topic", func(t *testing.T) {
handler.SetCipher(mockCipher)
Expand All @@ -380,7 +380,7 @@ func TestAPIV1RequestCloudSyncmgrPost(t *testing.T) {
mockHelper.EXPECT().Response(gomock.Any(), gomock.Any(), gomock.Eq(http.StatusOK)),
)

handler.APIV1RequestCloudSyncmgrPost(w, r)
handler.APIV1RequestCloudSyncmgrPublish(w, r)
})
t.Run("url", func(t *testing.T) {
handler.SetCipher(mockCipher)
Expand All @@ -403,7 +403,7 @@ func TestAPIV1RequestCloudSyncmgrPost(t *testing.T) {
mockHelper.EXPECT().Response(gomock.Any(), gomock.Any(), gomock.Eq(http.StatusOK)),
)

handler.APIV1RequestCloudSyncmgrPost(w, r)
handler.APIV1RequestCloudSyncmgrPublish(w, r)
})
})
})
Expand Down