[ISSUE-67901957] update api specs
diff --git a/accessEntity/api.go b/accessEntity/api.go index 4c3aa65..520224c 100644 --- a/accessEntity/api.go +++ b/accessEntity/api.go
@@ -439,7 +439,6 @@ } } cks := makeConsumerKeyStatusDetails(app, cd, devStatus) - //TODO: redirectUris details := makeAppCredentialDetails(appCred, cks, []string{app.CallbackUrl}, attrs) return &AppCredentialSuccessResponse{ AppCredential: details, @@ -495,7 +494,11 @@ credDetails = append(credDetails, detail) } - details, errRes := makeAppDetails(app, parStatus, prods, credDetails, attrs) + parent, errRes := a.getAppParent(app.ParentId, app.Type) + if errRes != nil { + return nil, errRes + } + details, errRes := makeAppDetails(app, parent, parStatus, prods, credDetails, attrs) if errRes != nil { return nil, errRes } @@ -509,6 +512,24 @@ }, nil } +func (a *ApiManager) getAppParent(id string, parentType string) (string, *common.ErrorResponse) { + switch parentType { + case AppTypeDeveloper: + return id, nil + case AppTypeCompany: + names, err := a.DbMan.GetComNames(id, TypeCompany) + if err != nil { + return "", newDbError(err) + } + if len(names) == 0 { + log.Warnf("getAppParent: No company with id=%v", id) + return "", nil + } + return names[0], nil + } + return "", nil +} + func makeConsumerKeyStatusDetails(app *common.App, c *CredentialDetails, devStatus string) *ConsumerKeyStatusDetails { return &ConsumerKeyStatusDetails{ AppCredential: c, @@ -531,7 +552,7 @@ ConsumerKeyStatus: cks, ConsumerSecret: ac.ConsumerSecret, DeveloperID: cks.DeveloperID, - RedirectUris: redirectUrl, //TODO + RedirectUris: redirectUrl, Scopes: common.JsonToStringArray(ac.Scopes), Status: ac.Status, } @@ -574,7 +595,7 @@ return a, nil } -func makeAppDetails(app *common.App, parentStatus string, prods []string, creds []*CredentialDetails, attrs []common.Attribute) (*AppDetails, *common.ErrorResponse) { +func makeAppDetails(app *common.App, parent string, parentStatus string, prods []string, creds []*CredentialDetails, attrs []common.Attribute) (*AppDetails, *common.ErrorResponse) { var a *AppDetails if app != nil { a = &AppDetails{ @@ -582,7 +603,7 @@ ApiProducts: prods, AppCredentials: creds, AppFamily: app.AppFamily, - AppParentID: app.ParentId, + AppParentID: parent, AppParentStatus: parentStatus, AppType: app.Type, Attributes: attrs, @@ -591,11 +612,9 @@ CreatedBy: app.CreatedBy, DisplayName: app.DisplayName, Id: app.Id, - KeyExpiresIn: "", //TODO LastModifiedAt: app.UpdatedAt, LastModifiedBy: app.UpdatedBy, Name: app.Name, - Scopes: []string{}, //TODO Status: app.Status, } } else {
diff --git a/accessEntity/api_response.go b/accessEntity/api_response.go index 6ebfb93..ea1e65c 100644 --- a/accessEntity/api_response.go +++ b/accessEntity/api_response.go
@@ -137,7 +137,7 @@ AppCredentials []*CredentialDetails `json:"appCredentials"` // app family AppFamily string `json:"appFamily"` - // app parent Id + // app parent, developer's Id or company's name AppParentID string `json:"appParentId"` // app parent status AppParentStatus string `json:"appParentStatus"` @@ -155,16 +155,12 @@ DisplayName string `json:"displayName"` // id Id string `json:"id"` - // key expires in - KeyExpiresIn string `json:"keyExpiresIn"` // ISO-8601 LastModifiedAt string `json:"lastModifiedAt"` // last modified by LastModifiedBy string `json:"lastModifiedBy"` // name Name string `json:"name"` - // scopes - Scopes []string `json:"scopes"` // status Status string `json:"status"` }
diff --git a/accessEntity/api_test.go b/accessEntity/api_test.go index f406e38..7f46f07 100644 --- a/accessEntity/api_test.go +++ b/accessEntity/api_test.go
@@ -185,6 +185,27 @@ }, } + testComApp := []common.App{ + { + Id: testId, + TenantId: "515211e9", + Name: "apstest", + DisplayName: "apstest", + AccessType: "READ", + CallbackUrl: "https://www.google.com", + Status: "APPROVED", + AppFamily: "default", + CompanyId: "a94f75e2-69b0-44af-8776-155df7c7d22e", + DeveloperId: "", + ParentId: "a94f75e2-69b0-44af-8776-155df7c7d22e", + Type: "COMPANY", + CreatedAt: "2017-08-18 22:13:18.325+00:00", + CreatedBy: "haoming@apid.git", + UpdatedAt: "2017-08-18 22:13:18.325+00:00", + UpdatedBy: "haoming@apid.git", + }, + } + testProductNames := []string{"foo", "bar"} testStatus := "test-status" testCreds := []common.AppCredential{ @@ -234,11 +255,9 @@ CreatedBy: testApp[0].CreatedBy, DisplayName: testApp[0].DisplayName, Id: testApp[0].Id, - KeyExpiresIn: "", //TODO LastModifiedAt: testApp[0].UpdatedAt, LastModifiedBy: testApp[0].UpdatedBy, Name: testApp[0].Name, - Scopes: []string{}, //TODO Status: testApp[0].Status, }, Organization: "test-org", @@ -248,8 +267,50 @@ SecondaryIdentifierValue: "test-dev", } + expectedComApp := AppSuccessResponse{ + App: &AppDetails{ + AccessType: testComApp[0].AccessType, + ApiProducts: testProductNames, + AppCredentials: []*CredentialDetails{ + { + ApiProductReferences: testProductNames, + AppID: testCreds[0].AppId, + AppStatus: testComApp[0].Status, + Attributes: attrs, + ConsumerKey: testCreds[0].Id, + ConsumerSecret: testCreds[0].ConsumerSecret, + ExpiresAt: testCreds[0].ExpiresAt, + IssuedAt: testCreds[0].IssuedAt, + MethodType: testCreds[0].MethodType, + Scopes: []string{"foo", "bar"}, + Status: testCreds[0].Status, + }, + }, + AppFamily: testComApp[0].AppFamily, + AppParentID: "testcompanyhflxv", + AppParentStatus: testStatus, + AppType: testComApp[0].Type, + Attributes: attrs, + CallbackUrl: testComApp[0].CallbackUrl, + CreatedAt: testComApp[0].CreatedAt, + CreatedBy: testComApp[0].CreatedBy, + DisplayName: testComApp[0].DisplayName, + Id: testComApp[0].Id, + LastModifiedAt: testComApp[0].UpdatedAt, + LastModifiedBy: testComApp[0].UpdatedBy, + Name: testComApp[0].Name, + Status: testComApp[0].Status, + }, + Organization: "test-org", + PrimaryIdentifierType: IdentifierAppName, + PrimaryIdentifierValue: "test-app", + SecondaryIdentifierType: IdentifierDeveloperId, + SecondaryIdentifierValue: "test-dev", + } + testData := [][]common.App{ testApp, + testComApp, nil, testApp, testApp, @@ -262,6 +323,11 @@ IdentifierAppName: {"test-app"}, IdentifierDeveloperId: {"test-dev"}, }, + { + IdentifierOrganization: {"test-org"}, + IdentifierAppName: {"test-app"}, + IdentifierDeveloperId: {"test-dev"}, + }, // negative { IdentifierOrganization: {"test-org"}, @@ -279,6 +345,7 @@ results := [][]interface{}{ {http.StatusOK, expected}, + {http.StatusOK, expectedComApp}, {http.StatusNotFound, nil}, {http.StatusBadRequest, nil}, {http.StatusBadRequest, nil}, @@ -289,6 +356,7 @@ dbMan.appCredentials = testCreds for i, data := range testData { dbMan.apps = data + dbMan.comNames = []string{"testcompanyhflxv"} code, body := clientGet(apiMan.AccessEntityPath+EndpointApp, testPars[i]) Expect(code).Should(Equal(results[i][0])) if results[i][1] != nil { @@ -550,7 +618,7 @@ }, ConsumerSecret: testAppCred[0].ConsumerSecret, DeveloperID: testApp[0].DeveloperId, - RedirectUris: []string{testApp[0].CallbackUrl}, //TODO + RedirectUris: []string{testApp[0].CallbackUrl}, Scopes: []string{"foo", "bar"}, Status: testAppCred[0].Status, },