mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 07:30:25 +00:00
MG-2441 - Add domain ID to API (#2442)
Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
This commit is contained in:
@@ -185,4 +185,7 @@ var (
|
||||
|
||||
// ErrLenSearchQuery indicates search query length.
|
||||
ErrLenSearchQuery = errors.New("search query must be at least 3 characters")
|
||||
|
||||
// ErrMissingDomainID indicates missing domainID.
|
||||
ErrMissingDomainID = errors.New("missing domainID")
|
||||
)
|
||||
|
||||
+16
-15
@@ -95,13 +95,13 @@ func (ts *BootstrapConfig) UnmarshalJSON(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) AddBootstrap(cfg BootstrapConfig, token string) (string, errors.SDKError) {
|
||||
func (sdk mgSDK) AddBootstrap(cfg BootstrapConfig, domainID, token string) (string, errors.SDKError) {
|
||||
data, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
return "", errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", sdk.bootstrapURL, configsEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, domainID, configsEndpoint)
|
||||
|
||||
headers, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusOK, http.StatusCreated)
|
||||
if sdkerr != nil {
|
||||
@@ -114,7 +114,8 @@ func (sdk mgSDK) AddBootstrap(cfg BootstrapConfig, token string) (string, errors
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Bootstraps(pm PageMetadata, token string) (BootstrapPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.bootstrapURL, configsEndpoint, pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, configsEndpoint)
|
||||
url, err := sdk.withQueryParams(sdk.bootstrapURL, endpoint, pm)
|
||||
if err != nil {
|
||||
return BootstrapPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -132,7 +133,7 @@ func (sdk mgSDK) Bootstraps(pm PageMetadata, token string) (BootstrapPage, error
|
||||
return bb, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Whitelist(thingID string, state int, token string) errors.SDKError {
|
||||
func (sdk mgSDK) Whitelist(thingID string, state int, domainID, token string) errors.SDKError {
|
||||
if thingID == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
@@ -142,18 +143,18 @@ func (sdk mgSDK) Whitelist(thingID string, state int, token string) errors.SDKEr
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, whitelistEndpoint, thingID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.bootstrapURL, domainID, whitelistEndpoint, thingID)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPut, url, token, data, nil, http.StatusCreated, http.StatusOK)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ViewBootstrap(id, token string) (BootstrapConfig, errors.SDKError) {
|
||||
func (sdk mgSDK) ViewBootstrap(id, domainID, token string) (BootstrapConfig, errors.SDKError) {
|
||||
if id == "" {
|
||||
return BootstrapConfig{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.bootstrapURL, domainID, configsEndpoint, id)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -168,11 +169,11 @@ func (sdk mgSDK) ViewBootstrap(id, token string) (BootstrapConfig, errors.SDKErr
|
||||
return bc, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKError {
|
||||
func (sdk mgSDK) UpdateBootstrap(cfg BootstrapConfig, domainID, token string) errors.SDKError {
|
||||
if cfg.ThingID == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, cfg.ThingID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.bootstrapURL, domainID, configsEndpoint, cfg.ThingID)
|
||||
|
||||
data, err := json.Marshal(cfg)
|
||||
if err != nil {
|
||||
@@ -184,11 +185,11 @@ func (sdk mgSDK) UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKEr
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateBootstrapCerts(id, clientCert, clientKey, ca, token string) (BootstrapConfig, errors.SDKError) {
|
||||
func (sdk mgSDK) UpdateBootstrapCerts(id, clientCert, clientKey, ca, domainID, token string) (BootstrapConfig, errors.SDKError) {
|
||||
if id == "" {
|
||||
return BootstrapConfig{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, bootstrapCertsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.bootstrapURL, domainID, bootstrapCertsEndpoint, id)
|
||||
request := BootstrapConfig{
|
||||
ClientCert: clientCert,
|
||||
ClientKey: clientKey,
|
||||
@@ -213,11 +214,11 @@ func (sdk mgSDK) UpdateBootstrapCerts(id, clientCert, clientKey, ca, token strin
|
||||
return bc, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateBootstrapConnection(id string, channels []string, token string) errors.SDKError {
|
||||
func (sdk mgSDK) UpdateBootstrapConnection(id string, channels []string, domainID, token string) errors.SDKError {
|
||||
if id == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, bootstrapConnEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.bootstrapURL, domainID, bootstrapConnEndpoint, id)
|
||||
request := map[string][]string{
|
||||
"channels": channels,
|
||||
}
|
||||
@@ -230,11 +231,11 @@ func (sdk mgSDK) UpdateBootstrapConnection(id string, channels []string, token s
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) RemoveBootstrap(id, token string) errors.SDKError {
|
||||
func (sdk mgSDK) RemoveBootstrap(id, domainID, token string) errors.SDKError {
|
||||
if id == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.bootstrapURL, domainID, configsEndpoint, id)
|
||||
|
||||
_, _, err := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
|
||||
return err
|
||||
|
||||
+201
-145
@@ -153,6 +153,7 @@ func TestAddBootstrap(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
cfg sdk.BootstrapConfig
|
||||
@@ -164,26 +165,29 @@ func TestAddBootstrap(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "add successfully",
|
||||
token: validToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrapConfig,
|
||||
svcRes: bootstrapConfig,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "add successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrapConfig,
|
||||
svcRes: bootstrapConfig,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "add with invalid token",
|
||||
token: invalidToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrapConfig,
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: svcerr.ErrAuthentication,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
desc: "add with invalid token",
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrapConfig,
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: svcerr.ErrAuthentication,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "add with config that cannot be marshalled",
|
||||
token: validToken,
|
||||
desc: "add with config that cannot be marshalled",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{
|
||||
Channels: map[string]interface{}{
|
||||
"channel1": make(chan int),
|
||||
@@ -204,42 +208,45 @@ func TestAddBootstrap(t *testing.T) {
|
||||
err: errors.NewSDKError(errMarshalChan),
|
||||
},
|
||||
{
|
||||
desc: "add an existing config",
|
||||
token: validToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrapConfig,
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: svcerr.ErrConflict,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrConflict, http.StatusConflict),
|
||||
desc: "add an existing config",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrapConfig,
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: svcerr.ErrConflict,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrConflict, http.StatusConflict),
|
||||
},
|
||||
{
|
||||
desc: "add empty config",
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{},
|
||||
svcReq: bootstrap.Config{},
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingID), http.StatusBadRequest),
|
||||
desc: "add empty config",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{},
|
||||
svcReq: bootstrap.Config{},
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingID), http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
desc: "add with non-existent thing Id",
|
||||
token: validToken,
|
||||
cfg: neID,
|
||||
svcReq: neReqId,
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: svcerr.ErrNotFound,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
desc: "add with non-existent thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: neID,
|
||||
svcReq: neReqId,
|
||||
svcRes: bootstrap.Config{},
|
||||
svcErr: svcerr.ErrNotFound,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("Add", mock.Anything, tc.session, tc.token, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
resp, err := mgsdk.AddBootstrap(tc.cfg, tc.token)
|
||||
resp, err := mgsdk.AddBootstrap(tc.cfg, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if err == nil {
|
||||
assert.Equal(t, bootstrapConfig.ThingID, resp)
|
||||
@@ -301,8 +308,9 @@ func TestListBootstraps(t *testing.T) {
|
||||
desc: "list successfully",
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcResp: bootstrap.ConfigsPage{
|
||||
Total: 1,
|
||||
@@ -321,8 +329,9 @@ func TestListBootstraps(t *testing.T) {
|
||||
desc: "list with invalid token",
|
||||
token: invalidToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcResp: bootstrap.ConfigsPage{},
|
||||
svcErr: svcerr.ErrAuthentication,
|
||||
@@ -333,8 +342,9 @@ func TestListBootstraps(t *testing.T) {
|
||||
desc: "list with empty token",
|
||||
token: "",
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcResp: bootstrap.ConfigsPage{},
|
||||
svcErr: nil,
|
||||
@@ -345,8 +355,9 @@ func TestListBootstraps(t *testing.T) {
|
||||
desc: "list with invalid query params",
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 1,
|
||||
Limit: 10,
|
||||
Offset: 1,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
Metadata: map[string]interface{}{
|
||||
"test": make(chan int),
|
||||
},
|
||||
@@ -360,8 +371,9 @@ func TestListBootstraps(t *testing.T) {
|
||||
desc: "list with response that cannot be unmarshalled",
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcResp: bootstrap.ConfigsPage{
|
||||
Total: 1,
|
||||
@@ -376,7 +388,7 @@ func TestListBootstraps(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("List", mock.Anything, tc.session, mock.Anything, tc.pageMeta.Offset, tc.pageMeta.Limit).Return(tc.svcResp, tc.svcErr)
|
||||
@@ -407,6 +419,7 @@ func TestWhiteList(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
thingID string
|
||||
@@ -417,25 +430,28 @@ func TestWhiteList(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "whitelist to active state successfully",
|
||||
token: validToken,
|
||||
thingID: thingId,
|
||||
state: active,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "whitelist to active state successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
thingID: thingId,
|
||||
state: active,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "whitelist to inactive state successfully",
|
||||
token: validToken,
|
||||
thingID: thingId,
|
||||
state: inactive,
|
||||
svcReq: bootstrap.Inactive,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "whitelist to inactive state successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
thingID: thingId,
|
||||
state: inactive,
|
||||
svcReq: bootstrap.Inactive,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "whitelist with invalid token",
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
thingID: thingId,
|
||||
state: active,
|
||||
@@ -444,41 +460,44 @@ func TestWhiteList(t *testing.T) {
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "whitelist with empty token",
|
||||
token: "",
|
||||
thingID: thingId,
|
||||
state: active,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
desc: "whitelist with empty token",
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
thingID: thingId,
|
||||
state: active,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "whitelist with invalid state",
|
||||
token: validToken,
|
||||
thingID: thingId,
|
||||
state: -1,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrBootstrapState), http.StatusBadRequest),
|
||||
desc: "whitelist with invalid state",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
thingID: thingId,
|
||||
state: -1,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrBootstrapState), http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
desc: "whitelist with empty thing Id",
|
||||
token: validToken,
|
||||
thingID: "",
|
||||
state: 1,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
desc: "whitelist with empty thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
thingID: "",
|
||||
state: 1,
|
||||
svcReq: bootstrap.Active,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("ChangeState", mock.Anything, tc.session, tc.token, tc.thingID, tc.svcReq).Return(tc.svcErr)
|
||||
err := mgsdk.Whitelist(tc.thingID, tc.state, tc.token)
|
||||
err := mgsdk.Whitelist(tc.thingID, tc.state, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if tc.err == nil {
|
||||
ok := svcCall.Parent.AssertCalled(t, "ChangeState", mock.Anything, tc.session, tc.token, tc.thingID, tc.svcReq)
|
||||
@@ -511,6 +530,7 @@ func TestViewBootstrap(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
id string
|
||||
@@ -522,6 +542,7 @@ func TestViewBootstrap(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "view successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
svcResp: bootstrapConfig,
|
||||
@@ -531,6 +552,7 @@ func TestViewBootstrap(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "view with invalid token",
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
id: thingId,
|
||||
svcResp: bootstrap.Config{},
|
||||
@@ -540,6 +562,7 @@ func TestViewBootstrap(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "view with empty token",
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
id: thingId,
|
||||
svcResp: bootstrap.Config{},
|
||||
@@ -549,6 +572,7 @@ func TestViewBootstrap(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "view with non-existent thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: invalid,
|
||||
svcResp: bootstrap.Config{},
|
||||
@@ -557,9 +581,10 @@ func TestViewBootstrap(t *testing.T) {
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrViewEntity, http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
desc: "view with response that cannot be unmarshalled",
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
desc: "view with response that cannot be unmarshalled",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
svcResp: bootstrap.Config{
|
||||
ThingID: thingId,
|
||||
Channels: []bootstrap.Channel{
|
||||
@@ -577,6 +602,7 @@ func TestViewBootstrap(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "view with empty thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: "",
|
||||
svcResp: bootstrap.Config{},
|
||||
@@ -588,11 +614,11 @@ func TestViewBootstrap(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("View", mock.Anything, tc.session, tc.id).Return(tc.svcResp, tc.svcErr)
|
||||
resp, err := mgsdk.ViewBootstrap(tc.id, tc.token)
|
||||
resp, err := mgsdk.ViewBootstrap(tc.id, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
assert.Equal(t, tc.response, resp)
|
||||
if err == nil {
|
||||
@@ -616,6 +642,7 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
cfg sdk.BootstrapConfig
|
||||
@@ -625,9 +652,10 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "update successfully",
|
||||
token: validToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
desc: "update successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrap.Config{
|
||||
ThingID: thingId,
|
||||
Name: bsName,
|
||||
@@ -637,9 +665,10 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "update with invalid token",
|
||||
token: invalidToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
desc: "update with invalid token",
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrap.Config{
|
||||
ThingID: thingId,
|
||||
Name: bsName,
|
||||
@@ -649,16 +678,18 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "update with empty token",
|
||||
token: "",
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrap.Config{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
desc: "update with empty token",
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
cfg: sdkBootstrapConfig,
|
||||
svcReq: bootstrap.Config{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "update with config that cannot be marshalled",
|
||||
token: validToken,
|
||||
desc: "update with config that cannot be marshalled",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{
|
||||
Channels: map[string]interface{}{
|
||||
"channel1": make(chan int),
|
||||
@@ -682,8 +713,9 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
err: errors.NewSDKError(errMarshalChan),
|
||||
},
|
||||
{
|
||||
desc: "update with non-existent thing Id",
|
||||
token: validToken,
|
||||
desc: "update with non-existent thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{
|
||||
ThingID: invalid,
|
||||
Channels: []sdk.Channel{
|
||||
@@ -705,8 +737,9 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
},
|
||||
{
|
||||
desc: "update with empty thing Id",
|
||||
token: validToken,
|
||||
desc: "update with empty thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{
|
||||
ThingID: "",
|
||||
Channels: []sdk.Channel{
|
||||
@@ -728,8 +761,9 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
},
|
||||
{
|
||||
desc: "update with config with only thing Id",
|
||||
token: validToken,
|
||||
desc: "update with config with only thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
cfg: sdk.BootstrapConfig{
|
||||
ThingID: thingId,
|
||||
},
|
||||
@@ -743,11 +777,11 @@ func TestUpdateBootstrap(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticationErr)
|
||||
svcCall := bsvc.On("Update", mock.Anything, tc.session, tc.svcReq).Return(tc.svcErr)
|
||||
err := mgsdk.UpdateBootstrap(tc.cfg, tc.token)
|
||||
err := mgsdk.UpdateBootstrap(tc.cfg, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if tc.err == nil {
|
||||
ok := svcCall.Parent.AssertCalled(t, "Update", mock.Anything, tc.session, tc.svcReq)
|
||||
@@ -777,6 +811,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
id string
|
||||
@@ -791,6 +826,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "update certs successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
clientCert: clientCert,
|
||||
@@ -803,6 +839,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update certs with invalid token",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
clientCert: clientCert,
|
||||
@@ -814,6 +851,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update certs with empty token",
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
id: thingId,
|
||||
clientCert: clientCert,
|
||||
@@ -825,6 +863,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update certs with non-existent thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: invalid,
|
||||
clientCert: clientCert,
|
||||
@@ -836,6 +875,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update certs with empty certs",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
clientCert: "",
|
||||
@@ -847,6 +887,7 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update certs with empty id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: "",
|
||||
clientCert: clientCert,
|
||||
@@ -859,11 +900,11 @@ func TestUpdateBootstrapCerts(t *testing.T) {
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("UpdateCert", mock.Anything, tc.session, tc.id, tc.clientCert, tc.clientKey, tc.caCert).Return(tc.svcResp, tc.svcErr)
|
||||
resp, err := mgsdk.UpdateBootstrapCerts(tc.id, tc.clientCert, tc.clientKey, tc.caCert, tc.token)
|
||||
resp, err := mgsdk.UpdateBootstrapCerts(tc.id, tc.clientCert, tc.clientKey, tc.caCert, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if err == nil {
|
||||
assert.Equal(t, tc.response, resp)
|
||||
@@ -884,6 +925,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
id string
|
||||
@@ -895,6 +937,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "update connection successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
channels: []string{channel1Id, channel2Id},
|
||||
@@ -903,6 +946,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update connection with invalid token",
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
id: thingId,
|
||||
channels: []string{channel1Id, channel2Id},
|
||||
@@ -911,6 +955,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update connection with empty token",
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
id: thingId,
|
||||
channels: []string{channel1Id, channel2Id},
|
||||
@@ -919,6 +964,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update connection with non-existent thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: invalid,
|
||||
channels: []string{channel1Id, channel2Id},
|
||||
@@ -927,6 +973,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update connection with non-existent channel Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
channels: []string{invalid},
|
||||
@@ -935,6 +982,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update connection with empty channels",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
channels: []string{},
|
||||
@@ -943,6 +991,7 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "update connection with empty id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: "",
|
||||
channels: []string{channel1Id, channel2Id},
|
||||
@@ -953,11 +1002,11 @@ func TestUpdateBootstrapConnection(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("UpdateConnections", mock.Anything, tc.session, tc.token, tc.id, tc.channels).Return(tc.svcErr)
|
||||
err := mgsdk.UpdateBootstrapConnection(tc.id, tc.channels, tc.token)
|
||||
err := mgsdk.UpdateBootstrapConnection(tc.id, tc.channels, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if tc.err == nil {
|
||||
ok := svcCall.Parent.AssertCalled(t, "UpdateConnections", mock.Anything, tc.session, tc.token, tc.id, tc.channels)
|
||||
@@ -980,6 +1029,7 @@ func TestRemoveBootstrap(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
id string
|
||||
@@ -988,56 +1038,62 @@ func TestRemoveBootstrap(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "remove successfully",
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "remove successfully",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "remove with invalid token",
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
id: thingId,
|
||||
authenticateErr: svcerr.ErrAuthentication,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "remove with non-existent thing Id",
|
||||
token: validToken,
|
||||
id: invalid,
|
||||
svcErr: svcerr.ErrNotFound,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
desc: "remove with non-existent thing Id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: invalid,
|
||||
svcErr: svcerr.ErrNotFound,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
},
|
||||
{
|
||||
desc: "remove removed bootstrap",
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
svcErr: svcerr.ErrNotFound,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
desc: "remove removed bootstrap",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: thingId,
|
||||
svcErr: svcerr.ErrNotFound,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrNotFound, http.StatusNotFound),
|
||||
},
|
||||
{
|
||||
desc: "remove with empty token",
|
||||
token: "",
|
||||
id: thingId,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
desc: "remove with empty token",
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
id: thingId,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "remove with empty id",
|
||||
token: validToken,
|
||||
id: "",
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
desc: "remove with empty id",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
id: "",
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := bsvc.On("Remove", mock.Anything, tc.session, tc.id).Return(tc.svcErr)
|
||||
err := mgsdk.RemoveBootstrap(tc.id, tc.token)
|
||||
err := mgsdk.RemoveBootstrap(tc.id, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if tc.err == nil {
|
||||
ok := svcCall.Parent.AssertCalled(t, "Remove", mock.Anything, tc.session, tc.id)
|
||||
|
||||
+8
-8
@@ -28,7 +28,7 @@ type Cert struct {
|
||||
ThingID string `json:"thing_id,omitempty"`
|
||||
}
|
||||
|
||||
func (sdk mgSDK) IssueCert(thingID, validity, token string) (Cert, errors.SDKError) {
|
||||
func (sdk mgSDK) IssueCert(thingID, validity, domainID, token string) (Cert, errors.SDKError) {
|
||||
r := certReq{
|
||||
ThingID: thingID,
|
||||
Validity: validity,
|
||||
@@ -38,7 +38,7 @@ func (sdk mgSDK) IssueCert(thingID, validity, token string) (Cert, errors.SDKErr
|
||||
return Cert{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", sdk.certsURL, certsEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.certsURL, domainID, certsEndpoint)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, d, nil, http.StatusCreated)
|
||||
if sdkerr != nil {
|
||||
@@ -52,8 +52,8 @@ func (sdk mgSDK) IssueCert(thingID, validity, token string) (Cert, errors.SDKErr
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ViewCert(id, token string) (Cert, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.certsURL, certsEndpoint, id)
|
||||
func (sdk mgSDK) ViewCert(id, domainID, token string) (Cert, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.certsURL, domainID, certsEndpoint, id)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -68,11 +68,11 @@ func (sdk mgSDK) ViewCert(id, token string) (Cert, errors.SDKError) {
|
||||
return cert, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ViewCertByThing(thingID, token string) (CertSerials, errors.SDKError) {
|
||||
func (sdk mgSDK) ViewCertByThing(thingID, domainID, token string) (CertSerials, errors.SDKError) {
|
||||
if thingID == "" {
|
||||
return CertSerials{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.certsURL, serialsEndpoint, thingID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.certsURL, domainID, serialsEndpoint, thingID)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -86,8 +86,8 @@ func (sdk mgSDK) ViewCertByThing(thingID, token string) (CertSerials, errors.SDK
|
||||
return cs, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) RevokeCert(id, token string) (time.Time, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.certsURL, certsEndpoint, id)
|
||||
func (sdk mgSDK) RevokeCert(id, domainID, token string) (time.Time, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.certsURL, domainID, certsEndpoint, id)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
|
||||
+100
-74
@@ -85,6 +85,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc string
|
||||
thingID string
|
||||
duration string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
authenticateErr error
|
||||
@@ -96,6 +97,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new cert with thing id and duration",
|
||||
thingID: thingID,
|
||||
duration: ttl,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{SerialNumber: serial},
|
||||
svcErr: nil,
|
||||
@@ -105,6 +107,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new cert with empty thing id and duration",
|
||||
thingID: "",
|
||||
duration: ttl,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertCreation, apiutil.ErrMissingID),
|
||||
@@ -114,6 +117,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new cert with invalid thing id and duration",
|
||||
thingID: invalid,
|
||||
duration: ttl,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertCreation, apiutil.ErrValidation),
|
||||
@@ -123,6 +127,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new cert with thing id and empty duration",
|
||||
thingID: thingID,
|
||||
duration: "",
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertCreation, apiutil.ErrMissingCertData),
|
||||
@@ -132,6 +137,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new cert with thing id and malformed duration",
|
||||
thingID: thingID,
|
||||
duration: invalid,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertCreation, apiutil.ErrInvalidCertData),
|
||||
@@ -141,6 +147,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new cert with empty token",
|
||||
thingID: thingID,
|
||||
duration: ttl,
|
||||
domainID: validID,
|
||||
token: "",
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertCreation, svcerr.ErrAuthentication),
|
||||
@@ -149,6 +156,7 @@ func TestIssueCert(t *testing.T) {
|
||||
{
|
||||
desc: "create new cert with invalid token",
|
||||
thingID: thingID,
|
||||
domainID: domainID,
|
||||
duration: ttl,
|
||||
token: invalidToken,
|
||||
svcRes: certs.Cert{},
|
||||
@@ -159,6 +167,7 @@ func TestIssueCert(t *testing.T) {
|
||||
desc: "create new empty cert",
|
||||
thingID: "",
|
||||
duration: "",
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertCreation, certs.ErrFailedCertCreation),
|
||||
@@ -172,12 +181,12 @@ func TestIssueCert(t *testing.T) {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("IssueCert", mock.Anything, tc.token, tc.thingID, tc.duration).Return(tc.svcRes, tc.svcErr)
|
||||
resp, err := mgsdk.IssueCert(tc.thingID, tc.duration, tc.token)
|
||||
svcCall := svc.On("IssueCert", mock.Anything, tc.domainID, tc.token, tc.thingID, tc.duration).Return(tc.svcRes, tc.svcErr)
|
||||
resp, err := mgsdk.IssueCert(tc.thingID, tc.duration, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if tc.err == nil {
|
||||
assert.Equal(t, tc.svcRes.SerialNumber, resp.SerialNumber)
|
||||
ok := svcCall.Parent.AssertCalled(t, "IssueCert", mock.Anything, tc.token, tc.thingID, tc.duration)
|
||||
ok := svcCall.Parent.AssertCalled(t, "IssueCert", mock.Anything, tc.domainID, tc.token, tc.thingID, tc.duration)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
svcCall.Unset()
|
||||
@@ -204,6 +213,7 @@ func TestViewCert(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
certID string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
authenticateErr error
|
||||
@@ -212,36 +222,40 @@ func TestViewCert(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "view existing cert",
|
||||
certID: validID,
|
||||
token: token,
|
||||
svcRes: cert,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "view existing cert",
|
||||
certID: validID,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: cert,
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "view non-existent cert",
|
||||
certID: invalid,
|
||||
token: token,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(svcerr.ErrNotFound, repoerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, svcerr.ErrNotFound), http.StatusNotFound),
|
||||
desc: "view non-existent cert",
|
||||
certID: invalid,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: errors.Wrap(svcerr.ErrNotFound, repoerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, svcerr.ErrNotFound), http.StatusNotFound),
|
||||
},
|
||||
{
|
||||
desc: "view cert with invalid token",
|
||||
certID: validID,
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
svcRes: certs.Cert{},
|
||||
authenticateErr: svcerr.ErrAuthentication,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "view cert with empty token",
|
||||
certID: validID,
|
||||
token: "",
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
desc: "view cert with empty token",
|
||||
certID: validID,
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
svcRes: certs.Cert{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -252,7 +266,7 @@ func TestViewCert(t *testing.T) {
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ViewCert", mock.Anything, tc.certID).Return(tc.svcRes, tc.svcErr)
|
||||
resp, err := mgsdk.ViewCert(tc.certID, tc.token)
|
||||
resp, err := mgsdk.ViewCert(tc.certID, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if err == nil {
|
||||
assert.Equal(t, viewCertRes, resp)
|
||||
@@ -285,6 +299,7 @@ func TestViewCertByThing(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
thingID string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
authenticateErr error
|
||||
@@ -293,44 +308,49 @@ func TestViewCertByThing(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "view existing cert",
|
||||
thingID: thingID,
|
||||
token: validToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{{SerialNumber: serial}}},
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "view existing cert",
|
||||
thingID: thingID,
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{{SerialNumber: serial}}},
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "view non-existent cert",
|
||||
thingID: invalid,
|
||||
token: validToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
svcErr: errors.Wrap(svcerr.ErrNotFound, repoerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, svcerr.ErrNotFound), http.StatusNotFound),
|
||||
desc: "view non-existent cert",
|
||||
thingID: invalid,
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
svcErr: errors.Wrap(svcerr.ErrNotFound, repoerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, svcerr.ErrNotFound), http.StatusNotFound),
|
||||
},
|
||||
{
|
||||
desc: "view cert with invalid token",
|
||||
thingID: thingID,
|
||||
domainID: domainID,
|
||||
token: invalidToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
authenticateErr: svcerr.ErrAuthentication,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "view cert with empty token",
|
||||
thingID: thingID,
|
||||
token: "",
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
desc: "view cert with empty token",
|
||||
thingID: thingID,
|
||||
domainID: domainID,
|
||||
token: "",
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "view cert with empty thing id",
|
||||
thingID: "",
|
||||
token: validToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
desc: "view cert with empty thing id",
|
||||
thingID: "",
|
||||
domainID: domainID,
|
||||
token: validToken,
|
||||
svcRes: certs.CertPage{Certificates: []certs.Cert{}},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKError(apiutil.ErrMissingID),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
@@ -340,7 +360,7 @@ func TestViewCertByThing(t *testing.T) {
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ListSerials", mock.Anything, tc.thingID, certs.PageMetadata{Revoked: defRevoke, Offset: defOffset, Limit: defLimit}).Return(tc.svcRes, tc.svcErr)
|
||||
resp, err := mgsdk.ViewCertByThing(tc.thingID, tc.token)
|
||||
resp, err := mgsdk.ViewCertByThing(tc.thingID, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if tc.err == nil {
|
||||
assert.Equal(t, viewCertThingRes, resp)
|
||||
@@ -368,6 +388,7 @@ func TestRevokeCert(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
thingID string
|
||||
domainID string
|
||||
token string
|
||||
session mgauthn.Session
|
||||
svcResp certs.Revoke
|
||||
@@ -376,44 +397,49 @@ func TestRevokeCert(t *testing.T) {
|
||||
err errors.SDKError
|
||||
}{
|
||||
{
|
||||
desc: "revoke cert successfully",
|
||||
thingID: thingID,
|
||||
token: validToken,
|
||||
svcResp: certs.Revoke{RevocationTime: time.Now()},
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
desc: "revoke cert successfully",
|
||||
thingID: thingID,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcResp: certs.Revoke{RevocationTime: time.Now()},
|
||||
svcErr: nil,
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "revoke cert with invalid token",
|
||||
thingID: thingID,
|
||||
domainID: validID,
|
||||
token: invalidToken,
|
||||
svcResp: certs.Revoke{},
|
||||
authenticateErr: svcerr.ErrAuthentication,
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "revoke non-existing cert",
|
||||
thingID: invalid,
|
||||
token: token,
|
||||
svcResp: certs.Revoke{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertRevocation, svcerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(certs.ErrFailedCertRevocation, http.StatusNotFound),
|
||||
desc: "revoke non-existing cert",
|
||||
thingID: invalid,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcResp: certs.Revoke{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedCertRevocation, svcerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(certs.ErrFailedCertRevocation, http.StatusNotFound),
|
||||
},
|
||||
{
|
||||
desc: "revoke cert with empty token",
|
||||
thingID: thingID,
|
||||
token: "",
|
||||
svcResp: certs.Revoke{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
desc: "revoke cert with empty token",
|
||||
thingID: thingID,
|
||||
domainID: validID,
|
||||
token: "",
|
||||
svcResp: certs.Revoke{},
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "revoke deleted cert",
|
||||
thingID: thingID,
|
||||
token: token,
|
||||
svcResp: certs.Revoke{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedToRemoveCertFromDB, svcerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(certs.ErrFailedToRemoveCertFromDB, http.StatusNotFound),
|
||||
desc: "revoke deleted cert",
|
||||
thingID: thingID,
|
||||
domainID: validID,
|
||||
token: validToken,
|
||||
svcResp: certs.Revoke{},
|
||||
svcErr: errors.Wrap(certs.ErrFailedToRemoveCertFromDB, svcerr.ErrNotFound),
|
||||
err: errors.NewSDKErrorWithStatus(certs.ErrFailedToRemoveCertFromDB, http.StatusNotFound),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
@@ -422,12 +448,12 @@ func TestRevokeCert(t *testing.T) {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("RevokeCert", mock.Anything, tc.token, tc.thingID).Return(tc.svcResp, tc.svcErr)
|
||||
resp, err := mgsdk.RevokeCert(tc.thingID, tc.token)
|
||||
svcCall := svc.On("RevokeCert", mock.Anything, tc.domainID, tc.token, tc.thingID).Return(tc.svcResp, tc.svcErr)
|
||||
resp, err := mgsdk.RevokeCert(tc.thingID, tc.domainID, tc.token)
|
||||
assert.Equal(t, tc.err, err)
|
||||
if err == nil {
|
||||
assert.NotEmpty(t, resp)
|
||||
ok := svcCall.Parent.AssertCalled(t, "RevokeCert", mock.Anything, tc.token, tc.thingID)
|
||||
ok := svcCall.Parent.AssertCalled(t, "RevokeCert", mock.Anything, tc.domainID, tc.token, tc.thingID)
|
||||
assert.True(t, ok)
|
||||
}
|
||||
svcCall.Unset()
|
||||
|
||||
+38
-37
@@ -32,12 +32,12 @@ type Channel struct {
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
func (sdk mgSDK) CreateChannel(c Channel, token string) (Channel, errors.SDKError) {
|
||||
func (sdk mgSDK) CreateChannel(c Channel, domainID, token string) (Channel, errors.SDKError) {
|
||||
data, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return Channel{}, errors.NewSDKError(err)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s", sdk.thingsURL, channelsEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
if sdkerr != nil {
|
||||
@@ -53,7 +53,8 @@ func (sdk mgSDK) CreateChannel(c Channel, token string) (Channel, errors.SDKErro
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Channels(pm PageMetadata, token string) (ChannelsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, channelsEndpoint, pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, channelsEndpoint)
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, endpoint, pm)
|
||||
if err != nil {
|
||||
return ChannelsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -71,8 +72,8 @@ func (sdk mgSDK) Channels(pm PageMetadata, token string) (ChannelsPage, errors.S
|
||||
return cp, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ChannelsByThing(thingID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(fmt.Sprintf("%s/things/%s", sdk.thingsURL, thingID), channelsEndpoint, pm)
|
||||
func (sdk mgSDK) ChannelsByThing(thingID string, pm PageMetadata, domainID, token string) (ChannelsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/things/%s", sdk.thingsURL, domainID, thingID), channelsEndpoint, pm)
|
||||
if err != nil {
|
||||
return ChannelsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -90,11 +91,11 @@ func (sdk mgSDK) ChannelsByThing(thingID string, pm PageMetadata, token string)
|
||||
return cp, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Channel(id, token string) (Channel, errors.SDKError) {
|
||||
func (sdk mgSDK) Channel(id, domainID, token string) (Channel, errors.SDKError) {
|
||||
if id == "" {
|
||||
return Channel{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, id)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -109,8 +110,8 @@ func (sdk mgSDK) Channel(id, token string) (Channel, errors.SDKError) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ChannelPermissions(id, token string) (Channel, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, id, permissionsEndpoint)
|
||||
func (sdk mgSDK) ChannelPermissions(id, domainID, token string) (Channel, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, id, permissionsEndpoint)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -125,11 +126,11 @@ func (sdk mgSDK) ChannelPermissions(id, token string) (Channel, errors.SDKError)
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateChannel(c Channel, token string) (Channel, errors.SDKError) {
|
||||
func (sdk mgSDK) UpdateChannel(c Channel, domainID, token string) (Channel, errors.SDKError) {
|
||||
if c.ID == "" {
|
||||
return Channel{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, c.ID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, c.ID)
|
||||
|
||||
data, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
@@ -149,32 +150,32 @@ func (sdk mgSDK) UpdateChannel(c Channel, token string) (Channel, errors.SDKErro
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) AddUserToChannel(channelID string, req UsersRelationRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) AddUserToChannel(channelID string, req UsersRelationRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, channelID, usersEndpoint, assignEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, channelID, usersEndpoint, assignEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) RemoveUserFromChannel(channelID string, req UsersRelationRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) RemoveUserFromChannel(channelID string, req UsersRelationRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, channelID, usersEndpoint, unassignEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, channelID, usersEndpoint, unassignEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListChannelUsers(channelID string, pm PageMetadata, token string) (UsersPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s", channelsEndpoint, channelID, usersEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, channelsEndpoint, channelID, usersEndpoint), pm)
|
||||
if err != nil {
|
||||
return UsersPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -190,32 +191,32 @@ func (sdk mgSDK) ListChannelUsers(channelID string, pm PageMetadata, token strin
|
||||
return up, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) AddUserGroupToChannel(channelID string, req UserGroupsRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) AddUserGroupToChannel(channelID string, req UserGroupsRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, channelID, groupsEndpoint, assignEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, channelID, groupsEndpoint, assignEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) RemoveUserGroupFromChannel(channelID string, req UserGroupsRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) RemoveUserGroupFromChannel(channelID string, req UserGroupsRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, channelID, groupsEndpoint, unassignEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, channelID, groupsEndpoint, unassignEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListChannelUserGroups(channelID string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s", channelsEndpoint, channelID, groupsEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, channelsEndpoint, channelID, groupsEndpoint), pm)
|
||||
if err != nil {
|
||||
return GroupsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -231,67 +232,67 @@ func (sdk mgSDK) ListChannelUserGroups(channelID string, pm PageMetadata, token
|
||||
return gp, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Connect(conn Connection, token string) errors.SDKError {
|
||||
func (sdk mgSDK) Connect(conn Connection, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(conn)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", sdk.thingsURL, connectEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, domainID, connectEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Disconnect(connIDs Connection, token string) errors.SDKError {
|
||||
func (sdk mgSDK) Disconnect(connIDs Connection, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(connIDs)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", sdk.thingsURL, disconnectEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, domainID, disconnectEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ConnectThing(thingID, channelID, token string) errors.SDKError {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, channelID, thingsEndpoint, thingID, connectEndpoint)
|
||||
func (sdk mgSDK) ConnectThing(thingID, channelID, domainID, token string) errors.SDKError {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, channelID, thingsEndpoint, thingID, connectEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusCreated)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DisconnectThing(thingID, channelID, token string) errors.SDKError {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, channelID, thingsEndpoint, thingID, disconnectEndpoint)
|
||||
func (sdk mgSDK) DisconnectThing(thingID, channelID, domainID, token string) errors.SDKError {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, channelID, thingsEndpoint, thingID, disconnectEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusNoContent)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) EnableChannel(id, token string) (Channel, errors.SDKError) {
|
||||
return sdk.changeChannelStatus(id, enableEndpoint, token)
|
||||
func (sdk mgSDK) EnableChannel(id, domainID, token string) (Channel, errors.SDKError) {
|
||||
return sdk.changeChannelStatus(id, enableEndpoint, domainID, token)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DisableChannel(id, token string) (Channel, errors.SDKError) {
|
||||
return sdk.changeChannelStatus(id, disableEndpoint, token)
|
||||
func (sdk mgSDK) DisableChannel(id, domainID, token string) (Channel, errors.SDKError) {
|
||||
return sdk.changeChannelStatus(id, disableEndpoint, domainID, token)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DeleteChannel(id, token string) errors.SDKError {
|
||||
func (sdk mgSDK) DeleteChannel(id, domainID, token string) errors.SDKError {
|
||||
if id == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, channelsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, id)
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) changeChannelStatus(id, status, token string) (Channel, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, channelsEndpoint, id, status)
|
||||
func (sdk mgSDK) changeChannelStatus(id, status, domainID, token string) (Channel, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, domainID, channelsEndpoint, id, status)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
|
||||
+307
-154
File diff suppressed because it is too large
Load Diff
+28
-25
@@ -39,12 +39,12 @@ type Group struct {
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
func (sdk mgSDK) CreateGroup(g Group, token string) (Group, errors.SDKError) {
|
||||
func (sdk mgSDK) CreateGroup(g Group, domainID, token string) (Group, errors.SDKError) {
|
||||
data, err := json.Marshal(g)
|
||||
if err != nil {
|
||||
return Group{}, errors.NewSDKError(err)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s", sdk.usersURL, groupsEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
if sdkerr != nil {
|
||||
@@ -60,7 +60,8 @@ func (sdk mgSDK) CreateGroup(g Group, token string) (Group, errors.SDKError) {
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Groups(pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, groupsEndpoint, pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, groupsEndpoint)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, endpoint, pm)
|
||||
if err != nil {
|
||||
return GroupsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -70,7 +71,8 @@ func (sdk mgSDK) Groups(pm PageMetadata, token string) (GroupsPage, errors.SDKEr
|
||||
|
||||
func (sdk mgSDK) Parents(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
|
||||
pm.Level = MaxLevel
|
||||
url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.usersURL, groupsEndpoint, id), "parents", pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, groupsEndpoint)
|
||||
url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.usersURL, endpoint, id), "parents", pm)
|
||||
if err != nil {
|
||||
return GroupsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -80,7 +82,8 @@ func (sdk mgSDK) Parents(id string, pm PageMetadata, token string) (GroupsPage,
|
||||
|
||||
func (sdk mgSDK) Children(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
|
||||
pm.Level = MaxLevel
|
||||
url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.usersURL, groupsEndpoint, id), "children", pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, groupsEndpoint)
|
||||
url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.usersURL, endpoint, id), "children", pm)
|
||||
if err != nil {
|
||||
return GroupsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -102,12 +105,12 @@ func (sdk mgSDK) getGroups(url, token string) (GroupsPage, errors.SDKError) {
|
||||
return tp, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Group(id, token string) (Group, errors.SDKError) {
|
||||
func (sdk mgSDK) Group(id, domainID, token string) (Group, errors.SDKError) {
|
||||
if id == "" {
|
||||
return Group{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.usersURL, groupsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, id)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -122,8 +125,8 @@ func (sdk mgSDK) Group(id, token string) (Group, errors.SDKError) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) GroupPermissions(id, token string) (Group, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.usersURL, groupsEndpoint, id, permissionsEndpoint)
|
||||
func (sdk mgSDK) GroupPermissions(id, domainID, token string) (Group, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, id, permissionsEndpoint)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
@@ -138,7 +141,7 @@ func (sdk mgSDK) GroupPermissions(id, token string) (Group, errors.SDKError) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateGroup(g Group, token string) (Group, errors.SDKError) {
|
||||
func (sdk mgSDK) UpdateGroup(g Group, domainID, token string) (Group, errors.SDKError) {
|
||||
data, err := json.Marshal(g)
|
||||
if err != nil {
|
||||
return Group{}, errors.NewSDKError(err)
|
||||
@@ -147,7 +150,7 @@ func (sdk mgSDK) UpdateGroup(g Group, token string) (Group, errors.SDKError) {
|
||||
if g.ID == "" {
|
||||
return Group{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.usersURL, groupsEndpoint, g.ID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, g.ID)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPut, url, token, data, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -162,40 +165,40 @@ func (sdk mgSDK) UpdateGroup(g Group, token string) (Group, errors.SDKError) {
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) EnableGroup(id, token string) (Group, errors.SDKError) {
|
||||
return sdk.changeGroupStatus(id, enableEndpoint, token)
|
||||
func (sdk mgSDK) EnableGroup(id, domainID, token string) (Group, errors.SDKError) {
|
||||
return sdk.changeGroupStatus(id, enableEndpoint, domainID, token)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DisableGroup(id, token string) (Group, errors.SDKError) {
|
||||
return sdk.changeGroupStatus(id, disableEndpoint, token)
|
||||
func (sdk mgSDK) DisableGroup(id, domainID, token string) (Group, errors.SDKError) {
|
||||
return sdk.changeGroupStatus(id, disableEndpoint, domainID, token)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) AddUserToGroup(groupID string, req UsersRelationRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) AddUserToGroup(groupID string, req UsersRelationRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.usersURL, groupsEndpoint, groupID, usersEndpoint, assignEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, groupID, usersEndpoint, assignEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) RemoveUserFromGroup(groupID string, req UsersRelationRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) RemoveUserFromGroup(groupID string, req UsersRelationRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.usersURL, groupsEndpoint, groupID, usersEndpoint, unassignEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, groupID, usersEndpoint, unassignEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListGroupUsers(groupID string, pm PageMetadata, token string) (UsersPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s", groupsEndpoint, groupID, usersEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, groupsEndpoint, groupID, usersEndpoint), pm)
|
||||
if err != nil {
|
||||
return UsersPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -212,7 +215,7 @@ func (sdk mgSDK) ListGroupUsers(groupID string, pm PageMetadata, token string) (
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListGroupChannels(groupID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s", groupsEndpoint, groupID, channelsEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, groupsEndpoint, groupID, channelsEndpoint), pm)
|
||||
if err != nil {
|
||||
return ChannelsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -228,17 +231,17 @@ func (sdk mgSDK) ListGroupChannels(groupID string, pm PageMetadata, token string
|
||||
return cp, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DeleteGroup(id, token string) errors.SDKError {
|
||||
func (sdk mgSDK) DeleteGroup(id, domainID, token string) errors.SDKError {
|
||||
if id == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.usersURL, groupsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, id)
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) changeGroupStatus(id, status, token string) (Group, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.usersURL, groupsEndpoint, id, status)
|
||||
func (sdk mgSDK) changeGroupStatus(id, status, domainID, token string) (Group, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.usersURL, domainID, groupsEndpoint, id, status)
|
||||
|
||||
_, body, err := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusOK)
|
||||
if err != nil {
|
||||
|
||||
+269
-177
File diff suppressed because it is too large
Load Diff
+11
-28
@@ -5,6 +5,7 @@ package sdk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -43,7 +44,7 @@ func (sdk mgSDK) SendInvitation(invitation Invitation, token string) (err error)
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := sdk.invitationsURL + "/" + invitationsEndpoint
|
||||
url := sdk.invitationsURL + "/" + invitation.DomainID + "/" + invitationsEndpoint
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
|
||||
@@ -51,7 +52,7 @@ func (sdk mgSDK) SendInvitation(invitation Invitation, token string) (err error)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Invitation(userID, domainID, token string) (invitation Invitation, err error) {
|
||||
url := sdk.invitationsURL + "/" + invitationsEndpoint + "/" + userID + "/" + domainID
|
||||
url := sdk.invitationsURL + "/" + domainID + "/" + invitationsEndpoint + "/" + usersEndpoint + "/" + userID
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -66,7 +67,9 @@ func (sdk mgSDK) Invitation(userID, domainID, token string) (invitation Invitati
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Invitations(pm PageMetadata, token string) (invitations InvitationPage, err error) {
|
||||
url, err := sdk.withQueryParams(sdk.invitationsURL, invitationsEndpoint, pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, invitationsEndpoint)
|
||||
|
||||
url, err := sdk.withQueryParams(sdk.invitationsURL, endpoint, pm)
|
||||
if err != nil {
|
||||
return InvitationPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -85,43 +88,23 @@ func (sdk mgSDK) Invitations(pm PageMetadata, token string) (invitations Invitat
|
||||
}
|
||||
|
||||
func (sdk mgSDK) AcceptInvitation(domainID, token string) (err error) {
|
||||
req := struct {
|
||||
DomainID string `json:"domain_id"`
|
||||
}{
|
||||
DomainID: domainID,
|
||||
}
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
url := sdk.invitationsURL + "/" + domainID + "/" + invitationsEndpoint + "/" + acceptEndpoint
|
||||
|
||||
url := sdk.invitationsURL + "/" + invitationsEndpoint + "/" + acceptEndpoint
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusNoContent)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) RejectInvitation(domainID, token string) (err error) {
|
||||
req := struct {
|
||||
DomainID string `json:"domain_id"`
|
||||
}{
|
||||
DomainID: domainID,
|
||||
}
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
url := sdk.invitationsURL + "/" + domainID + "/" + invitationsEndpoint + "/" + rejectEndpoint
|
||||
|
||||
url := sdk.invitationsURL + "/" + invitationsEndpoint + "/" + rejectEndpoint
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusNoContent)
|
||||
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DeleteInvitation(userID, domainID, token string) (err error) {
|
||||
url := sdk.invitationsURL + "/" + invitationsEndpoint + "/" + userID + "/" + domainID
|
||||
url := sdk.invitationsURL + "/" + domainID + "/" + invitationsEndpoint + "/" + usersEndpoint + "/" + userID
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
|
||||
|
||||
|
||||
@@ -205,16 +205,6 @@ func TestViewInvitation(t *testing.T) {
|
||||
response: sdk.Invitation{},
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "view invitation with empty userID",
|
||||
token: validToken,
|
||||
userID: "",
|
||||
domainID: invitation.DomainID,
|
||||
svcRes: invitations.Invitation{},
|
||||
svcErr: nil,
|
||||
response: sdk.Invitation{},
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingID), http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
desc: "view invitation with invalid domainID",
|
||||
token: validToken,
|
||||
@@ -229,7 +219,7 @@ func TestViewInvitation(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == valid {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ViewInvitation", mock.Anything, tc.session, tc.userID, tc.domainID).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -271,12 +261,14 @@ func TestListInvitation(t *testing.T) {
|
||||
desc: "list invitations successfully",
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: invitations.Page{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcRes: invitations.InvitationPage{
|
||||
Total: 1,
|
||||
@@ -293,8 +285,9 @@ func TestListInvitation(t *testing.T) {
|
||||
desc: "list invitations with invalid token",
|
||||
token: invalidToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: invitations.Page{
|
||||
Offset: 0,
|
||||
@@ -306,20 +299,32 @@ func TestListInvitation(t *testing.T) {
|
||||
err: errors.NewSDKErrorWithStatus(svcerr.ErrAuthentication, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "list invitations with empty token",
|
||||
token: "",
|
||||
pageMeta: sdk.PageMetadata{},
|
||||
desc: "list invitations with empty token",
|
||||
token: "",
|
||||
pageMeta: sdk.PageMetadata{
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcRes: invitations.InvitationPage{},
|
||||
svcErr: nil,
|
||||
response: sdk.InvitationPage{},
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "list invitations with empty domainID",
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{},
|
||||
svcRes: invitations.InvitationPage{},
|
||||
svcErr: nil,
|
||||
response: sdk.InvitationPage{},
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingDomainID), http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
desc: "list invitations with limit greater than max limit",
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 101,
|
||||
Offset: 0,
|
||||
Limit: 101,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: invitations.Page{},
|
||||
svcRes: invitations.InvitationPage{},
|
||||
@@ -523,14 +528,6 @@ func TestDeleteInvitation(t *testing.T) {
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(apiutil.ErrBearerToken, http.StatusUnauthorized),
|
||||
},
|
||||
{
|
||||
desc: "delete invitation with empty userID",
|
||||
token: validToken,
|
||||
userID: "",
|
||||
domainID: invitation.DomainID,
|
||||
svcErr: nil,
|
||||
err: errors.NewSDKErrorWithStatus(errors.Wrap(apiutil.ErrValidation, apiutil.ErrMissingID), http.StatusBadRequest),
|
||||
},
|
||||
{
|
||||
desc: "delete invitation with invalid domainID",
|
||||
token: validToken,
|
||||
|
||||
+98
-95
@@ -175,6 +175,7 @@ type SDK interface {
|
||||
// pm := sdk.PageMetadata{
|
||||
// Offset: 0,
|
||||
// Limit: 10,
|
||||
// DomainID: "domainID"
|
||||
// }
|
||||
// members, _ := sdk.Members("groupID", pm, "token")
|
||||
// fmt.Println(members)
|
||||
@@ -353,13 +354,13 @@ type SDK interface {
|
||||
// example:
|
||||
// thing := sdk.Thing{
|
||||
// Name: "My Thing",
|
||||
// Metadata: sdk.Metadata{
|
||||
// Metadata: sdk.Metadata{"domain_1"
|
||||
// "key": "value",
|
||||
// },
|
||||
// }
|
||||
// thing, _ := sdk.CreateThing(thing, "token")
|
||||
// thing, _ := sdk.CreateThing(thing, "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
CreateThing(thing Thing, token string) (Thing, errors.SDKError)
|
||||
CreateThing(thing Thing, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// CreateThings registers new things and returns their ids.
|
||||
//
|
||||
@@ -378,9 +379,9 @@ type SDK interface {
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// things, _ := sdk.CreateThings(things, "token")
|
||||
// things, _ := sdk.CreateThings(things, "domainID", "token")
|
||||
// fmt.Println(things)
|
||||
CreateThings(things []Thing, token string) ([]Thing, errors.SDKError)
|
||||
CreateThings(things []Thing, domainID, token string) ([]Thing, errors.SDKError)
|
||||
|
||||
// Filters things and returns a page result.
|
||||
//
|
||||
@@ -409,16 +410,16 @@ type SDK interface {
|
||||
// Thing returns thing object by id.
|
||||
//
|
||||
// example:
|
||||
// thing, _ := sdk.Thing("thingID", "token")
|
||||
// thing, _ := sdk.Thing("thingID", "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
Thing(id, token string) (Thing, errors.SDKError)
|
||||
Thing(id, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// ThingPermissions returns user permissions on the thing id.
|
||||
//
|
||||
// example:
|
||||
// thing, _ := sdk.Thing("thingID", "token")
|
||||
// thing, _ := sdk.Thing("thingID", "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
ThingPermissions(id, token string) (Thing, errors.SDKError)
|
||||
ThingPermissions(id, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// UpdateThing updates existing thing.
|
||||
//
|
||||
@@ -430,9 +431,9 @@ type SDK interface {
|
||||
// "key": "value",
|
||||
// },
|
||||
// }
|
||||
// thing, _ := sdk.UpdateThing(thing, "token")
|
||||
// thing, _ := sdk.UpdateThing(thing, "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
UpdateThing(thing Thing, token string) (Thing, errors.SDKError)
|
||||
UpdateThing(thing Thing, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// UpdateThingTags updates the client's tags.
|
||||
//
|
||||
@@ -441,30 +442,30 @@ type SDK interface {
|
||||
// ID: "thingID",
|
||||
// Tags: []string{"tag1", "tag2"},
|
||||
// }
|
||||
// thing, _ := sdk.UpdateThingTags(thing, "token")
|
||||
// thing, _ := sdk.UpdateThingTags(thing, "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
UpdateThingTags(thing Thing, token string) (Thing, errors.SDKError)
|
||||
UpdateThingTags(thing Thing, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// UpdateThingSecret updates the client's secret
|
||||
//
|
||||
// example:
|
||||
// thing, err := sdk.UpdateThingSecret("thingID", "newSecret", "token")
|
||||
// thing, err := sdk.UpdateThingSecret("thingID", "newSecret", "domainID," "token")
|
||||
// fmt.Println(thing)
|
||||
UpdateThingSecret(id, secret, token string) (Thing, errors.SDKError)
|
||||
UpdateThingSecret(id, secret, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// EnableThing changes client status to enabled.
|
||||
//
|
||||
// example:
|
||||
// thing, _ := sdk.EnableThing("thingID", "token")
|
||||
// thing, _ := sdk.EnableThing("thingID", "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
EnableThing(id, token string) (Thing, errors.SDKError)
|
||||
EnableThing(id, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// DisableThing changes client status to disabled - soft delete.
|
||||
//
|
||||
// example:
|
||||
// thing, _ := sdk.DisableThing("thingID", "token")
|
||||
// thing, _ := sdk.DisableThing("thingID", "domainID", "token")
|
||||
// fmt.Println(thing)
|
||||
DisableThing(id, token string) (Thing, errors.SDKError)
|
||||
DisableThing(id, domainID, token string) (Thing, errors.SDKError)
|
||||
|
||||
// ShareThing shares thing with other users.
|
||||
//
|
||||
@@ -473,9 +474,9 @@ type SDK interface {
|
||||
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
|
||||
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
|
||||
// }
|
||||
// err := sdk.ShareThing("thing_id", req, "token")
|
||||
// err := sdk.ShareThing("thing_id", req, "domainID","token")
|
||||
// fmt.Println(err)
|
||||
ShareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError
|
||||
ShareThing(thingID string, req UsersRelationRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// UnshareThing unshare a thing with other users.
|
||||
//
|
||||
@@ -484,9 +485,9 @@ type SDK interface {
|
||||
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
|
||||
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
|
||||
// }
|
||||
// err := sdk.UnshareThing("thing_id", req, "token")
|
||||
// err := sdk.UnshareThing("thing_id", req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
UnshareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError
|
||||
UnshareThing(thingID string, req UsersRelationRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// ListThingUsers all users in a thing.
|
||||
//
|
||||
@@ -503,9 +504,9 @@ type SDK interface {
|
||||
// DeleteThing deletes a thing with the given id.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.DeleteThing("thingID", "token")
|
||||
// err := sdk.DeleteThing("thingID", "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
DeleteThing(id, token string) errors.SDKError
|
||||
DeleteThing(id, domainID, token string) errors.SDKError
|
||||
|
||||
// CreateGroup creates new group and returns its id.
|
||||
//
|
||||
@@ -516,9 +517,9 @@ type SDK interface {
|
||||
// "key": "value",
|
||||
// },
|
||||
// }
|
||||
// group, _ := sdk.CreateGroup(group, "token")
|
||||
// group, _ := sdk.CreateGroup(group, "domainID", "token")
|
||||
// fmt.Println(group)
|
||||
CreateGroup(group Group, token string) (Group, errors.SDKError)
|
||||
CreateGroup(group Group, domainID, token string) (Group, errors.SDKError)
|
||||
|
||||
// Groups returns page of groups.
|
||||
//
|
||||
@@ -559,16 +560,16 @@ type SDK interface {
|
||||
// Group returns users group object by id.
|
||||
//
|
||||
// example:
|
||||
// group, _ := sdk.Group("groupID", "token")
|
||||
// group, _ := sdk.Group("groupID", "domainID", "token")
|
||||
// fmt.Println(group)
|
||||
Group(id, token string) (Group, errors.SDKError)
|
||||
Group(id, domainID, token string) (Group, errors.SDKError)
|
||||
|
||||
// GroupPermissions returns user permissions by group ID.
|
||||
//
|
||||
// example:
|
||||
// group, _ := sdk.Group("groupID", "token")
|
||||
// group, _ := sdk.Group("groupID", "domainID" "token")
|
||||
// fmt.Println(group)
|
||||
GroupPermissions(id, token string) (Group, errors.SDKError)
|
||||
GroupPermissions(id, domainID, token string) (Group, errors.SDKError)
|
||||
|
||||
// UpdateGroup updates existing group.
|
||||
//
|
||||
@@ -580,23 +581,23 @@ type SDK interface {
|
||||
// "key": "value",
|
||||
// },
|
||||
// }
|
||||
// group, _ := sdk.UpdateGroup(group, "token")
|
||||
// group, _ := sdk.UpdateGroup(group, "domainID", "token")
|
||||
// fmt.Println(group)
|
||||
UpdateGroup(group Group, token string) (Group, errors.SDKError)
|
||||
UpdateGroup(group Group, domainID, token string) (Group, errors.SDKError)
|
||||
|
||||
// EnableGroup changes group status to enabled.
|
||||
//
|
||||
// example:
|
||||
// group, _ := sdk.EnableGroup("groupID", "token")
|
||||
// group, _ := sdk.EnableGroup("groupID", "domainID", "token")
|
||||
// fmt.Println(group)
|
||||
EnableGroup(id, token string) (Group, errors.SDKError)
|
||||
EnableGroup(id, domainID, token string) (Group, errors.SDKError)
|
||||
|
||||
// DisableGroup changes group status to disabled - soft delete.
|
||||
//
|
||||
// example:
|
||||
// group, _ := sdk.DisableGroup("groupID", "token")
|
||||
// group, _ := sdk.DisableGroup("groupID", "domainID", "token")
|
||||
// fmt.Println(group)
|
||||
DisableGroup(id, token string) (Group, errors.SDKError)
|
||||
DisableGroup(id, domainID, token string) (Group, errors.SDKError)
|
||||
|
||||
// AddUserToGroup add user to a group.
|
||||
//
|
||||
@@ -605,9 +606,9 @@ type SDK interface {
|
||||
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
|
||||
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
|
||||
// }
|
||||
// err := sdk.AddUserToGroup("groupID",req, "token")
|
||||
// err := sdk.AddUserToGroup("groupID",req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
AddUserToGroup(groupID string, req UsersRelationRequest, token string) errors.SDKError
|
||||
AddUserToGroup(groupID string, req UsersRelationRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// RemoveUserFromGroup remove user from a group.
|
||||
//
|
||||
@@ -616,9 +617,9 @@ type SDK interface {
|
||||
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
|
||||
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
|
||||
// }
|
||||
// err := sdk.RemoveUserFromGroup("groupID",req, "token")
|
||||
// err := sdk.RemoveUserFromGroup("groupID",req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
RemoveUserFromGroup(groupID string, req UsersRelationRequest, token string) errors.SDKError
|
||||
RemoveUserFromGroup(groupID string, req UsersRelationRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// ListGroupUsers list all users in the group id .
|
||||
//
|
||||
@@ -638,6 +639,7 @@ type SDK interface {
|
||||
// pm := sdk.PageMetadata{
|
||||
// Offset: 0,
|
||||
// Limit: 10,
|
||||
// DomainID: "domain"
|
||||
// Permission: "edit", // available Options: "administrator", "administrator", "delete", edit", "view", "share", "owner", "owner", "admin", "editor", "contributor", "editor", "viewer", "guest", "create"
|
||||
// }
|
||||
// groups, _ := sdk.ListGroupChannels("groupID", pm, "token")
|
||||
@@ -647,9 +649,9 @@ type SDK interface {
|
||||
// DeleteGroup delete given group id.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.DeleteGroup("groupID", "token")
|
||||
// err := sdk.DeleteGroup("groupID", "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
DeleteGroup(id, token string) errors.SDKError
|
||||
DeleteGroup(id, domainID, token string) errors.SDKError
|
||||
|
||||
// CreateChannel creates new channel and returns its id.
|
||||
//
|
||||
@@ -660,9 +662,9 @@ type SDK interface {
|
||||
// "key": "value",
|
||||
// },
|
||||
// }
|
||||
// channel, _ := sdk.CreateChannel(channel, "token")
|
||||
// channel, _ := sdk.CreateChannel(channel, "domainID", "token")
|
||||
// fmt.Println(channel)
|
||||
CreateChannel(channel Channel, token string) (Channel, errors.SDKError)
|
||||
CreateChannel(channel Channel, domainID, token string) (Channel, errors.SDKError)
|
||||
|
||||
// Channels returns page of channels.
|
||||
//
|
||||
@@ -671,6 +673,7 @@ type SDK interface {
|
||||
// Offset: 0,
|
||||
// Limit: 10,
|
||||
// Name: "My Channel",
|
||||
// Domain: "domainID"
|
||||
// }
|
||||
// channels, _ := sdk.Channels(pm, "token")
|
||||
// fmt.Println(channels)
|
||||
@@ -684,23 +687,23 @@ type SDK interface {
|
||||
// Limit: 10,
|
||||
// Name: "My Channel",
|
||||
// }
|
||||
// channels, _ := sdk.ChannelsByThing("thingID", pm, "token")
|
||||
// channels, _ := sdk.ChannelsByThing("thingID", pm, "domainID" "token")
|
||||
// fmt.Println(channels)
|
||||
ChannelsByThing(thingID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
|
||||
ChannelsByThing(thingID string, pm PageMetadata, domainID, token string) (ChannelsPage, errors.SDKError)
|
||||
|
||||
// Channel returns channel data by id.
|
||||
//
|
||||
// example:
|
||||
// channel, _ := sdk.Channel("channelID", "token")
|
||||
// channel, _ := sdk.Channel("channelID", "domainID", "token")
|
||||
// fmt.Println(channel)
|
||||
Channel(id, token string) (Channel, errors.SDKError)
|
||||
Channel(id, domainID, token string) (Channel, errors.SDKError)
|
||||
|
||||
// ChannelPermissions returns user permissions on the channel ID.
|
||||
//
|
||||
// example:
|
||||
// channel, _ := sdk.Channel("channelID", "token")
|
||||
// channel, _ := sdk.Channel("channelID", "domainID", "token")
|
||||
// fmt.Println(channel)
|
||||
ChannelPermissions(id, token string) (Channel, errors.SDKError)
|
||||
ChannelPermissions(id, domainID, token string) (Channel, errors.SDKError)
|
||||
|
||||
// UpdateChannel updates existing channel.
|
||||
//
|
||||
@@ -712,23 +715,23 @@ type SDK interface {
|
||||
// "key": "value",
|
||||
// },
|
||||
// }
|
||||
// channel, _ := sdk.UpdateChannel(channel, "token")
|
||||
// channel, _ := sdk.UpdateChannel(channel, "domainID", "token")
|
||||
// fmt.Println(channel)
|
||||
UpdateChannel(channel Channel, token string) (Channel, errors.SDKError)
|
||||
UpdateChannel(channel Channel, domainID, token string) (Channel, errors.SDKError)
|
||||
|
||||
// EnableChannel changes channel status to enabled.
|
||||
//
|
||||
// example:
|
||||
// channel, _ := sdk.EnableChannel("channelID", "token")
|
||||
// channel, _ := sdk.EnableChannel("channelID", "domainID", "token")
|
||||
// fmt.Println(channel)
|
||||
EnableChannel(id, token string) (Channel, errors.SDKError)
|
||||
EnableChannel(id, domainID, token string) (Channel, errors.SDKError)
|
||||
|
||||
// DisableChannel changes channel status to disabled - soft delete.
|
||||
//
|
||||
// example:
|
||||
// channel, _ := sdk.DisableChannel("channelID", "token")
|
||||
// channel, _ := sdk.DisableChannel("channelID", "domainID", "token")
|
||||
// fmt.Println(channel)
|
||||
DisableChannel(id, token string) (Channel, errors.SDKError)
|
||||
DisableChannel(id, domainID, token string) (Channel, errors.SDKError)
|
||||
|
||||
// AddUserToChannel add user to a channel.
|
||||
//
|
||||
@@ -737,9 +740,9 @@ type SDK interface {
|
||||
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
|
||||
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
|
||||
// }
|
||||
// err := sdk.AddUserToChannel("channel_id", req, "token")
|
||||
// err := sdk.AddUserToChannel("channel_id", req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
AddUserToChannel(channelID string, req UsersRelationRequest, token string) errors.SDKError
|
||||
AddUserToChannel(channelID string, req UsersRelationRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// RemoveUserFromChannel remove user from a group.
|
||||
//
|
||||
@@ -748,9 +751,9 @@ type SDK interface {
|
||||
// Relation: "contributor", // available options: "owner", "admin", "editor", "contributor", "guest"
|
||||
// UserIDs: ["user_id_1", "user_id_2", "user_id_3"]
|
||||
// }
|
||||
// err := sdk.RemoveUserFromChannel("channel_id", req, "token")
|
||||
// err := sdk.RemoveUserFromChannel("channel_id", req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
RemoveUserFromChannel(channelID string, req UsersRelationRequest, token string) errors.SDKError
|
||||
RemoveUserFromChannel(channelID string, req UsersRelationRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// ListChannelUsers list all users in a channel .
|
||||
//
|
||||
@@ -770,9 +773,9 @@ type SDK interface {
|
||||
// req := sdk.UserGroupsRequest{
|
||||
// GroupsIDs: ["group_id_1", "group_id_2", "group_id_3"]
|
||||
// }
|
||||
// err := sdk.AddUserGroupToChannel("channel_id",req, "token")
|
||||
// err := sdk.AddUserGroupToChannel("channel_id",req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
AddUserGroupToChannel(channelID string, req UserGroupsRequest, token string) errors.SDKError
|
||||
AddUserGroupToChannel(channelID string, req UserGroupsRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// RemoveUserGroupFromChannel remove user group from a channel.
|
||||
//
|
||||
@@ -780,9 +783,9 @@ type SDK interface {
|
||||
// req := sdk.UserGroupsRequest{
|
||||
// GroupsIDs: ["group_id_1", "group_id_2", "group_id_3"]
|
||||
// }
|
||||
// err := sdk.RemoveUserGroupFromChannel("channel_id",req, "token")
|
||||
// err := sdk.RemoveUserGroupFromChannel("channel_id",req, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
RemoveUserGroupFromChannel(channelID string, req UserGroupsRequest, token string) errors.SDKError
|
||||
RemoveUserGroupFromChannel(channelID string, req UserGroupsRequest, domainID, token string) errors.SDKError
|
||||
|
||||
// ListChannelUserGroups list all user groups in a channel.
|
||||
//
|
||||
@@ -799,9 +802,9 @@ type SDK interface {
|
||||
// DeleteChannel delete given group id.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.DeleteChannel("channelID", "token")
|
||||
// err := sdk.DeleteChannel("channelID", "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
DeleteChannel(id, token string) errors.SDKError
|
||||
DeleteChannel(id, domainID, token string) errors.SDKError
|
||||
|
||||
// Connect bulk connects things to channels specified by id.
|
||||
//
|
||||
@@ -810,9 +813,9 @@ type SDK interface {
|
||||
// ChannelID: "channel_id_1",
|
||||
// ThingID: "thing_id_1",
|
||||
// }
|
||||
// err := sdk.Connect(conns, "token")
|
||||
// err := sdk.Connect(conns, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
Connect(conns Connection, token string) errors.SDKError
|
||||
Connect(conns Connection, domainID, token string) errors.SDKError
|
||||
|
||||
// Disconnect
|
||||
//
|
||||
@@ -821,9 +824,9 @@ type SDK interface {
|
||||
// ChannelID: "channel_id_1",
|
||||
// ThingID: "thing_id_1",
|
||||
// }
|
||||
// err := sdk.Disconnect(conns, "token")
|
||||
// err := sdk.Disconnect(conns, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
Disconnect(connIDs Connection, token string) errors.SDKError
|
||||
Disconnect(connIDs Connection, domainID, token string) errors.SDKError
|
||||
|
||||
// ConnectThing connects thing to specified channel by id.
|
||||
//
|
||||
@@ -832,7 +835,7 @@ type SDK interface {
|
||||
// example:
|
||||
// err := sdk.ConnectThing("thingID", "channelID", "token")
|
||||
// fmt.Println(err)
|
||||
ConnectThing(thingID, chanID, token string) errors.SDKError
|
||||
ConnectThing(thingID, chanID, domainID, token string) errors.SDKError
|
||||
|
||||
// DisconnectThing disconnect thing from specified channel by id.
|
||||
//
|
||||
@@ -841,7 +844,7 @@ type SDK interface {
|
||||
// example:
|
||||
// err := sdk.DisconnectThing("thingID", "channelID", "token")
|
||||
// fmt.Println(err)
|
||||
DisconnectThing(thingID, chanID, token string) errors.SDKError
|
||||
DisconnectThing(thingID, chanID, domainID, token string) errors.SDKError
|
||||
|
||||
// SendMessage send message to specified channel.
|
||||
//
|
||||
@@ -886,16 +889,16 @@ type SDK interface {
|
||||
// ExternalKey: "externalKey",
|
||||
// Channels: []string{"channel1", "channel2"},
|
||||
// }
|
||||
// id, _ := sdk.AddBootstrap(cfg, "token")
|
||||
// id, _ := sdk.AddBootstrap(cfg, "domainID", "token")
|
||||
// fmt.Println(id)
|
||||
AddBootstrap(cfg BootstrapConfig, token string) (string, errors.SDKError)
|
||||
AddBootstrap(cfg BootstrapConfig, domainID, token string) (string, errors.SDKError)
|
||||
|
||||
// View returns Thing Config with given ID belonging to the user identified by the given token.
|
||||
//
|
||||
// example:
|
||||
// bootstrap, _ := sdk.ViewBootstrap("id", "token")
|
||||
// bootstrap, _ := sdk.ViewBootstrap("id", "domainID", "token")
|
||||
// fmt.Println(bootstrap)
|
||||
ViewBootstrap(id, token string) (BootstrapConfig, errors.SDKError)
|
||||
ViewBootstrap(id, domainID, token string) (BootstrapConfig, errors.SDKError)
|
||||
|
||||
// Update updates editable fields of the provided Config.
|
||||
//
|
||||
@@ -907,30 +910,30 @@ type SDK interface {
|
||||
// ExternalKey: "externalKey",
|
||||
// Channels: []string{"channel1", "channel2"},
|
||||
// }
|
||||
// err := sdk.UpdateBootstrap(cfg, "token")
|
||||
// err := sdk.UpdateBootstrap(cfg, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKError
|
||||
UpdateBootstrap(cfg BootstrapConfig, domainID, token string) errors.SDKError
|
||||
|
||||
// Update bootstrap config certificates.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.UpdateBootstrapCerts("id", "clientCert", "clientKey", "ca", "token")
|
||||
// err := sdk.UpdateBootstrapCerts("id", "clientCert", "clientKey", "ca", "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
UpdateBootstrapCerts(id string, clientCert, clientKey, ca string, token string) (BootstrapConfig, errors.SDKError)
|
||||
UpdateBootstrapCerts(id string, clientCert, clientKey, ca string, domainID, token string) (BootstrapConfig, errors.SDKError)
|
||||
|
||||
// UpdateBootstrapConnection updates connections performs update of the channel list corresponding Thing is connected to.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.UpdateBootstrapConnection("id", []string{"channel1", "channel2"}, "token")
|
||||
// err := sdk.UpdateBootstrapConnection("id", []string{"channel1", "channel2"}, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
UpdateBootstrapConnection(id string, channels []string, token string) errors.SDKError
|
||||
UpdateBootstrapConnection(id string, channels []string, domainID, token string) errors.SDKError
|
||||
|
||||
// Remove removes Config with specified token that belongs to the user identified by the given token.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.RemoveBootstrap("id", "token")
|
||||
// err := sdk.RemoveBootstrap("id", "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
RemoveBootstrap(id, token string) errors.SDKError
|
||||
RemoveBootstrap(id, domainID, token string) errors.SDKError
|
||||
|
||||
// Bootstrap returns Config to the Thing with provided external ID using external key.
|
||||
//
|
||||
@@ -960,37 +963,37 @@ type SDK interface {
|
||||
// Whitelist updates Thing state Config with given ID belonging to the user identified by the given token.
|
||||
//
|
||||
// example:
|
||||
// err := sdk.Whitelist("thingID", 1, "token")
|
||||
// err := sdk.Whitelist("thingID", 1, "domainID", "token")
|
||||
// fmt.Println(err)
|
||||
Whitelist(thingID string, state int, token string) errors.SDKError
|
||||
Whitelist(thingID string, state int, domainID, token string) errors.SDKError
|
||||
|
||||
// IssueCert issues a certificate for a thing required for mTLS.
|
||||
//
|
||||
// example:
|
||||
// cert, _ := sdk.IssueCert("thingID", "24h", "token")
|
||||
// cert, _ := sdk.IssueCert("thingID", "24h", "domainID", "token")
|
||||
// fmt.Println(cert)
|
||||
IssueCert(thingID, validity, token string) (Cert, errors.SDKError)
|
||||
IssueCert(thingID, validity, domainID, token string) (Cert, errors.SDKError)
|
||||
|
||||
// ViewCert returns a certificate given certificate ID
|
||||
//
|
||||
// example:
|
||||
// cert, _ := sdk.ViewCert("certID", "token")
|
||||
// cert, _ := sdk.ViewCert("certID", "domainID", "token")
|
||||
// fmt.Println(cert)
|
||||
ViewCert(certID, token string) (Cert, errors.SDKError)
|
||||
ViewCert(certID, domainID, token string) (Cert, errors.SDKError)
|
||||
|
||||
// ViewCertByThing retrieves a list of certificates' serial IDs for a given thing ID.
|
||||
//
|
||||
// example:
|
||||
// cserial, _ := sdk.ViewCertByThing("thingID", "token")
|
||||
// cserial, _ := sdk.ViewCertByThing("thingID", "domainID", "token")
|
||||
// fmt.Println(cserial)
|
||||
ViewCertByThing(thingID, token string) (CertSerials, errors.SDKError)
|
||||
ViewCertByThing(thingID, domainID, token string) (CertSerials, errors.SDKError)
|
||||
|
||||
// RevokeCert revokes certificate for thing with thingID
|
||||
//
|
||||
// example:
|
||||
// tm, _ := sdk.RevokeCert("thingID", "token")
|
||||
// tm, _ := sdk.RevokeCert("thingID", "domainID", "token")
|
||||
// fmt.Println(tm)
|
||||
RevokeCert(thingID, token string) (time.Time, errors.SDKError)
|
||||
RevokeCert(thingID, domainID, token string) (time.Time, errors.SDKError)
|
||||
|
||||
// CreateSubscription creates a new subscription
|
||||
//
|
||||
|
||||
@@ -24,7 +24,6 @@ const (
|
||||
invalidIdentity = "invalididentity"
|
||||
Identity = "identity"
|
||||
secret = "strongsecret"
|
||||
token = "token"
|
||||
invalidToken = "invalid"
|
||||
contentType = "application/senml+json"
|
||||
invalid = "invalid"
|
||||
|
||||
+30
-29
@@ -37,13 +37,13 @@ type Thing struct {
|
||||
Permissions []string `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
func (sdk mgSDK) CreateThing(thing Thing, token string) (Thing, errors.SDKError) {
|
||||
func (sdk mgSDK) CreateThing(thing Thing, domainID, token string) (Thing, errors.SDKError) {
|
||||
data, err := json.Marshal(thing)
|
||||
if err != nil {
|
||||
return Thing{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", sdk.thingsURL, thingsEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
if sdkerr != nil {
|
||||
@@ -58,13 +58,13 @@ func (sdk mgSDK) CreateThing(thing Thing, token string) (Thing, errors.SDKError)
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) CreateThings(things []Thing, token string) ([]Thing, errors.SDKError) {
|
||||
func (sdk mgSDK) CreateThings(things []Thing, domainID, token string) ([]Thing, errors.SDKError) {
|
||||
data, err := json.Marshal(things)
|
||||
if err != nil {
|
||||
return []Thing{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, "bulk")
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, "bulk")
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -80,7 +80,8 @@ func (sdk mgSDK) CreateThings(things []Thing, token string) ([]Thing, errors.SDK
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Things(pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, thingsEndpoint, pm)
|
||||
endpoint := fmt.Sprintf("%s/%s", pm.DomainID, thingsEndpoint)
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, endpoint, pm)
|
||||
if err != nil {
|
||||
return ThingsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -99,7 +100,7 @@ func (sdk mgSDK) Things(pm PageMetadata, token string) (ThingsPage, errors.SDKEr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ThingsByChannel(chanID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("channels/%s/%s", chanID, thingsEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/channels/%s/%s", pm.DomainID, chanID, thingsEndpoint), pm)
|
||||
if err != nil {
|
||||
return ThingsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -117,11 +118,11 @@ func (sdk mgSDK) ThingsByChannel(chanID string, pm PageMetadata, token string) (
|
||||
return tp, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Thing(id, token string) (Thing, errors.SDKError) {
|
||||
func (sdk mgSDK) Thing(id, domainID, token string) (Thing, errors.SDKError) {
|
||||
if id == "" {
|
||||
return Thing{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, id)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -136,8 +137,8 @@ func (sdk mgSDK) Thing(id, token string) (Thing, errors.SDKError) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ThingPermissions(id, token string) (Thing, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, id, permissionsEndpoint)
|
||||
func (sdk mgSDK) ThingPermissions(id, domainID, token string) (Thing, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, id, permissionsEndpoint)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, nil, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -152,11 +153,11 @@ func (sdk mgSDK) ThingPermissions(id, token string) (Thing, errors.SDKError) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateThing(t Thing, token string) (Thing, errors.SDKError) {
|
||||
func (sdk mgSDK) UpdateThing(t Thing, domainID, token string) (Thing, errors.SDKError) {
|
||||
if t.ID == "" {
|
||||
return Thing{}, errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, t.ID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, t.ID)
|
||||
|
||||
data, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
@@ -176,13 +177,13 @@ func (sdk mgSDK) UpdateThing(t Thing, token string) (Thing, errors.SDKError) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateThingTags(t Thing, token string) (Thing, errors.SDKError) {
|
||||
func (sdk mgSDK) UpdateThingTags(t Thing, domainID, token string) (Thing, errors.SDKError) {
|
||||
data, err := json.Marshal(t)
|
||||
if err != nil {
|
||||
return Thing{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/tags", sdk.thingsURL, thingsEndpoint, t.ID)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/tags", sdk.thingsURL, domainID, thingsEndpoint, t.ID)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -197,7 +198,7 @@ func (sdk mgSDK) UpdateThingTags(t Thing, token string) (Thing, errors.SDKError)
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UpdateThingSecret(id, secret, token string) (Thing, errors.SDKError) {
|
||||
func (sdk mgSDK) UpdateThingSecret(id, secret, domainID, token string) (Thing, errors.SDKError) {
|
||||
ucsr := updateThingSecretReq{Secret: secret}
|
||||
|
||||
data, err := json.Marshal(ucsr)
|
||||
@@ -205,7 +206,7 @@ func (sdk mgSDK) UpdateThingSecret(id, secret, token string) (Thing, errors.SDKE
|
||||
return Thing{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/secret", sdk.thingsURL, thingsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/secret", sdk.thingsURL, domainID, thingsEndpoint, id)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPatch, url, token, data, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -220,16 +221,16 @@ func (sdk mgSDK) UpdateThingSecret(id, secret, token string) (Thing, errors.SDKE
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) EnableThing(id, token string) (Thing, errors.SDKError) {
|
||||
return sdk.changeThingStatus(id, enableEndpoint, token)
|
||||
func (sdk mgSDK) EnableThing(id, domainID, token string) (Thing, errors.SDKError) {
|
||||
return sdk.changeThingStatus(id, enableEndpoint, domainID, token)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DisableThing(id, token string) (Thing, errors.SDKError) {
|
||||
return sdk.changeThingStatus(id, disableEndpoint, token)
|
||||
func (sdk mgSDK) DisableThing(id, domainID, token string) (Thing, errors.SDKError) {
|
||||
return sdk.changeThingStatus(id, disableEndpoint, domainID, token)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) changeThingStatus(id, status, token string) (Thing, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, id, status)
|
||||
func (sdk mgSDK) changeThingStatus(id, status, domainID, token string) (Thing, errors.SDKError) {
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, id, status)
|
||||
|
||||
_, body, sdkerr := sdk.processRequest(http.MethodPost, url, token, nil, nil, http.StatusOK)
|
||||
if sdkerr != nil {
|
||||
@@ -244,32 +245,32 @@ func (sdk mgSDK) changeThingStatus(id, status, token string) (Thing, errors.SDKE
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ShareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) ShareThing(thingID string, req UsersRelationRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, thingID, shareEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, thingID, shareEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusCreated)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) UnshareThing(thingID string, req UsersRelationRequest, token string) errors.SDKError {
|
||||
func (sdk mgSDK) UnshareThing(thingID string, req UsersRelationRequest, domainID, token string) errors.SDKError {
|
||||
data, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, thingsEndpoint, thingID, unshareEndpoint)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, thingID, unshareEndpoint)
|
||||
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListThingUsers(thingID string, pm PageMetadata, token string) (UsersPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s", thingsEndpoint, thingID, usersEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, thingsEndpoint, thingID, usersEndpoint), pm)
|
||||
if err != nil {
|
||||
return UsersPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -286,11 +287,11 @@ func (sdk mgSDK) ListThingUsers(thingID string, pm PageMetadata, token string) (
|
||||
return up, nil
|
||||
}
|
||||
|
||||
func (sdk mgSDK) DeleteThing(id, token string) errors.SDKError {
|
||||
func (sdk mgSDK) DeleteThing(id, domainID, token string) errors.SDKError {
|
||||
if id == "" {
|
||||
return errors.NewSDKError(apiutil.ErrMissingID)
|
||||
}
|
||||
url := fmt.Sprintf("%s/%s/%s", sdk.thingsURL, thingsEndpoint, id)
|
||||
url := fmt.Sprintf("%s/%s/%s/%s", sdk.thingsURL, domainID, thingsEndpoint, id)
|
||||
_, _, sdkerr := sdk.processRequest(http.MethodDelete, url, token, nil, nil, http.StatusNoContent)
|
||||
return sdkerr
|
||||
}
|
||||
|
||||
+260
-154
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -80,7 +80,7 @@ func (sdk mgSDK) Users(pm PageMetadata, token string) (UsersPage, errors.SDKErro
|
||||
}
|
||||
|
||||
func (sdk mgSDK) Members(groupID string, meta PageMetadata, token string) (UsersPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s", groupsEndpoint, groupID, usersEndpoint), meta)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s/%s", meta.DomainID, groupsEndpoint, groupID, usersEndpoint), meta)
|
||||
if err != nil {
|
||||
return UsersPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -277,7 +277,7 @@ func (sdk mgSDK) UpdateUserRole(user User, token string) (User, errors.SDKError)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListUserChannels(userID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s", usersEndpoint, userID, channelsEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, usersEndpoint, userID, channelsEndpoint), pm)
|
||||
if err != nil {
|
||||
return ChannelsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func (sdk mgSDK) ListUserChannels(userID string, pm PageMetadata, token string)
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListUserGroups(userID string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s", usersEndpoint, userID, groupsEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.usersURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, usersEndpoint, userID, groupsEndpoint), pm)
|
||||
if err != nil {
|
||||
return GroupsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
@@ -312,7 +312,7 @@ func (sdk mgSDK) ListUserGroups(userID string, pm PageMetadata, token string) (G
|
||||
}
|
||||
|
||||
func (sdk mgSDK) ListUserThings(userID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s", usersEndpoint, userID, thingsEndpoint), pm)
|
||||
url, err := sdk.withQueryParams(sdk.thingsURL, fmt.Sprintf("%s/%s/%s/%s", pm.DomainID, usersEndpoint, userID, thingsEndpoint), pm)
|
||||
if err != nil {
|
||||
return ThingsPage{}, errors.NewSDKError(err)
|
||||
}
|
||||
|
||||
+66
-50
@@ -33,7 +33,10 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
var id = generateUUID(&testing.T{})
|
||||
var (
|
||||
id = generateUUID(&testing.T{})
|
||||
domainID = "c717fa97-ffd9-40cb-8cf9-7c2859059395"
|
||||
)
|
||||
|
||||
func setupUsers() (*httptest.Server, *umocks.Service, *authnmocks.Authentication) {
|
||||
usvc := new(umocks.Service)
|
||||
@@ -291,7 +294,7 @@ func TestListUsers(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
desc: "list users successfully",
|
||||
token: token,
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
@@ -352,7 +355,7 @@ func TestListUsers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "list users with zero limit",
|
||||
token: token,
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: offset,
|
||||
Limit: 0,
|
||||
@@ -379,7 +382,7 @@ func TestListUsers(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "list users with limit greater than max",
|
||||
token: token,
|
||||
token: validToken,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: offset,
|
||||
Limit: 101,
|
||||
@@ -536,7 +539,7 @@ func TestListUsers(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ListClients", mock.Anything, tc.session, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -667,7 +670,7 @@ func TestSearchClients(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}, tc.authenticateErr)
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}, tc.authenticateErr)
|
||||
svcCall := svc.On("SearchUsers", mock.Anything, mock.Anything).Return(tc.searchreturn, tc.err)
|
||||
page, err := mgsdk.SearchUsers(tc.page, tc.token)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
|
||||
@@ -763,7 +766,7 @@ func TestViewUser(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ViewClient", mock.Anything, tc.session, tc.userID).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -842,7 +845,7 @@ func TestUserProfile(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ViewProfile", mock.Anything, tc.session).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1006,7 +1009,7 @@ func TestUpdateUser(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("UpdateClient", mock.Anything, tc.session, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1164,7 +1167,7 @@ func TestUpdateUserTags(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("UpdateClientTags", mock.Anything, tc.session, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1312,7 +1315,7 @@ func TestUpdateUserIdentity(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("UpdateClientIdentity", mock.Anything, tc.session, tc.updateClientReq.ID, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1417,7 +1420,7 @@ func TestResetPassword(t *testing.T) {
|
||||
{
|
||||
desc: "reset password successfully",
|
||||
token: validToken,
|
||||
session: mgauthn.Session{UserID: validID, DomainID: validID},
|
||||
session: mgauthn.Session{UserID: validID, DomainID: domainID},
|
||||
newPassword: newPassword,
|
||||
confPassword: newPassword,
|
||||
svcErr: nil,
|
||||
@@ -1442,7 +1445,7 @@ func TestResetPassword(t *testing.T) {
|
||||
{
|
||||
desc: "reset password with empty new password",
|
||||
token: validToken,
|
||||
session: mgauthn.Session{UserID: validID, DomainID: validID},
|
||||
session: mgauthn.Session{UserID: validID, DomainID: domainID},
|
||||
newPassword: "",
|
||||
confPassword: newPassword,
|
||||
svcErr: nil,
|
||||
@@ -1451,7 +1454,7 @@ func TestResetPassword(t *testing.T) {
|
||||
{
|
||||
desc: "reset password with empty confirm password",
|
||||
token: validToken,
|
||||
session: mgauthn.Session{UserID: validID, DomainID: validID},
|
||||
session: mgauthn.Session{UserID: validID, DomainID: domainID},
|
||||
newPassword: newPassword,
|
||||
confPassword: "",
|
||||
svcErr: nil,
|
||||
@@ -1460,7 +1463,7 @@ func TestResetPassword(t *testing.T) {
|
||||
{
|
||||
desc: "reset password with new password not matching confirm password",
|
||||
token: validToken,
|
||||
session: mgauthn.Session{UserID: validID, DomainID: validID},
|
||||
session: mgauthn.Session{UserID: validID, DomainID: domainID},
|
||||
newPassword: newPassword,
|
||||
confPassword: "wrongPassword",
|
||||
svcErr: nil,
|
||||
@@ -1469,7 +1472,7 @@ func TestResetPassword(t *testing.T) {
|
||||
{
|
||||
desc: "reset password with weak password",
|
||||
token: validToken,
|
||||
session: mgauthn.Session{UserID: validID, DomainID: validID},
|
||||
session: mgauthn.Session{UserID: validID, DomainID: domainID},
|
||||
newPassword: "weak",
|
||||
confPassword: "weak",
|
||||
svcErr: nil,
|
||||
@@ -1479,7 +1482,7 @@ func TestResetPassword(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ResetSecret", mock.Anything, tc.session, tc.newPassword).Return(tc.svcErr)
|
||||
@@ -1610,7 +1613,7 @@ func TestUpdatePassword(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("UpdateClientSecret", mock.Anything, tc.session, tc.oldPassword, tc.newPassword).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1767,7 +1770,7 @@ func TestUpdateUserRole(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("UpdateClientRole", mock.Anything, tc.session, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1839,7 +1842,7 @@ func TestEnableUser(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("EnableClient", mock.Anything, tc.session, tc.userID).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1944,7 +1947,7 @@ func TestDisableUser(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("DisableClient", mock.Anything, tc.session, tc.userID).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -1989,8 +1992,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: validToken,
|
||||
groupID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: mgclients.Page{
|
||||
Offset: 0,
|
||||
@@ -2016,8 +2020,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: invalidToken,
|
||||
groupID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: mgclients.Page{
|
||||
Offset: 0,
|
||||
@@ -2033,8 +2038,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: "",
|
||||
groupID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: mgclients.Page{},
|
||||
svcErr: nil,
|
||||
@@ -2046,8 +2052,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: validToken,
|
||||
groupID: wrongID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: mgclients.Page{
|
||||
Offset: 0,
|
||||
@@ -2063,8 +2070,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: validToken,
|
||||
groupID: "",
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: mgclients.Page{},
|
||||
svcErr: nil,
|
||||
@@ -2076,8 +2084,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: validToken,
|
||||
groupID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
Metadata: map[string]interface{}{
|
||||
"test": make(chan int),
|
||||
},
|
||||
@@ -2093,8 +2102,9 @@ func TestListMembers(t *testing.T) {
|
||||
token: validToken,
|
||||
groupID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: mgclients.Page{
|
||||
Offset: 0,
|
||||
@@ -2121,7 +2131,7 @@ func TestListMembers(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ListMembers", mock.Anything, tc.session, "groups", tc.groupID, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
@@ -2195,7 +2205,7 @@ func TestDeleteUser(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("DeleteClient", mock.Anything, tc.session, tc.userID).Return(tc.svcErr)
|
||||
@@ -2239,8 +2249,9 @@ func TestListUserGroups(t *testing.T) {
|
||||
token: validToken,
|
||||
userID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: groups.Page{
|
||||
PageMeta: groups.PageMeta{
|
||||
@@ -2270,8 +2281,9 @@ func TestListUserGroups(t *testing.T) {
|
||||
token: invalidToken,
|
||||
userID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: groups.Page{
|
||||
PageMeta: groups.PageMeta{
|
||||
@@ -2296,8 +2308,9 @@ func TestListUserGroups(t *testing.T) {
|
||||
token: "",
|
||||
userID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: groups.Page{},
|
||||
svcErr: nil,
|
||||
@@ -2309,8 +2322,9 @@ func TestListUserGroups(t *testing.T) {
|
||||
token: validToken,
|
||||
userID: wrongID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: groups.Page{
|
||||
PageMeta: groups.PageMeta{
|
||||
@@ -2330,8 +2344,9 @@ func TestListUserGroups(t *testing.T) {
|
||||
token: validToken,
|
||||
userID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
Metadata: map[string]interface{}{
|
||||
"test": make(chan int),
|
||||
},
|
||||
@@ -2347,8 +2362,9 @@ func TestListUserGroups(t *testing.T) {
|
||||
token: validToken,
|
||||
userID: validID,
|
||||
pageMeta: sdk.PageMetadata{
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
Offset: 0,
|
||||
Limit: 10,
|
||||
DomainID: domainID,
|
||||
},
|
||||
svcReq: groups.Page{
|
||||
PageMeta: groups.PageMeta{
|
||||
@@ -2378,7 +2394,7 @@ func TestListUserGroups(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
if tc.token == validToken {
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: validID}
|
||||
tc.session = mgauthn.Session{DomainUserID: validID, UserID: validID, DomainID: domainID}
|
||||
}
|
||||
authCall := auth.On("Authenticate", mock.Anything, tc.token).Return(tc.session, tc.authenticateErr)
|
||||
svcCall := svc.On("ListGroups", mock.Anything, tc.session, "users", tc.userID, tc.svcReq).Return(tc.svcRes, tc.svcErr)
|
||||
|
||||
+356
-356
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user