Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fetch spec with authentication application registry #4661

Merged
merged 31 commits into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7387cf3
Added dependency to the authorization package defined in the Applicat…
akgalwas Jun 19, 2019
b04bb06
Started implementing fetching spec with credentials
akgalwas Jun 19, 2019
b9ef533
Change Application Registry download.client to use authorization staf…
Maladie Jun 27, 2019
3ae38eb
Downloader tests added
Maladie Jun 28, 2019
2ff6b45
Modified data model to include credentials for fetching API spec
akgalwas Jun 28, 2019
bfa675d
Updated data model and tests
akgalwas Jun 28, 2019
09f7ae6
Updated data model and tests
akgalwas Jul 1, 2019
584d474
Dep ensure fix
akgalwas Jul 1, 2019
7b25c8d
CSRF token removed
Maladie Jul 1, 2019
685ad1e
Merge remote-tracking branch 'akgalwas/fetch-spec-with-authentication…
Maladie Jul 1, 2019
a8a6a5e
Added converting from externalApi/model to metadata/model
akgalwas Jul 1, 2019
1939ab1
csrf package moved to internal
Maladie Jul 1, 2019
c3ed4cc
Merge remote-tracking branch 'akgalwas/fetch-spec-with-authentication…
Maladie Jul 1, 2019
a74bb24
Removed CertificateGen from the model for getting specification
akgalwas Jul 2, 2019
bb23866
Build issue fix (goimports)
akgalwas Jul 2, 2019
f278c40
Custom headers and query parameters in fetching spec
Maladie Jul 2, 2019
ceaa205
Merge remote-tracking branch 'akgalwas/fetch-spec-with-authentication…
Maladie Jul 2, 2019
3ed5552
dependencies fix
Maladie Jul 2, 2019
0d4f575
Fix for fetching token for specification
akgalwas Jul 3, 2019
cf642e0
Specification.service switched to use SpecificationRequestParameters
Maladie Jul 3, 2019
2dc516b
Merge remote-tracking branch 'akgalwas/fetch-spec-with-authentication…
Maladie Jul 3, 2019
126fcda
Fix for using headers and query params for fetching specification
akgalwas Jul 3, 2019
d18ca4b
Minor fixes
akgalwas Jul 3, 2019
3b5de7b
Added flag for insecure spec fetching
akgalwas Jul 3, 2019
0a570dc
Build fix
akgalwas Jul 3, 2019
c13e9ae
Code review #1 simplified internal data model
akgalwas Jul 4, 2019
1449c5e
Code review #2 fixed comments in internal data model
akgalwas Jul 4, 2019
69be4a7
Code review #4 removed useless code
akgalwas Jul 4, 2019
68bbfaf
Code review #5 returning 502 in case Oauth call failed when getting spec
akgalwas Jul 4, 2019
7e67ff8
Update dependencies
Szymongib Jul 5, 2019
88fb748
Merge branch 'fetch-spec-with-authentication-application-registry' of…
Szymongib Jul 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions components/application-registry/Gopkg.lock

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

2 changes: 1 addition & 1 deletion components/application-registry/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ required = [

[[constraint]]
name = "github.com/kyma-project/kyma"
revision = "dd9f72adc14c41e129824770011f37722dc5bbff"
revision = "ba297749ad3c81d2786c3e9acaaa8751d0a2a2db"

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewSpecificationService(dynamicClient dynamic.Interface, opt *options) spec
uploadClient := upload.NewClient(opt.uploadServiceURL)
assetStoreService := assetstore.NewService(docsTopicRepository, uploadClient, opt.insecureAssetDownload, opt.assetstoreRequestTimeout)

return specification.NewSpecService(assetStoreService, opt.specRequestTimeout)
return specification.NewSpecService(assetStoreService, opt.specRequestTimeout, opt.insecureSpecDownload)
}

func newApplicationRepository(config *restclient.Config) (applications.ServiceRepository, apperrors.AppError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type options struct {
detailedErrorResponse bool
uploadServiceURL string
insecureAssetDownload bool
insecureSpecDownload bool
}

func parseArgs() *options {
Expand All @@ -30,6 +31,7 @@ func parseArgs() *options {
detailedErrorResponse := flag.Bool("detailedErrorResponse", false, "Flag for showing full internal error response messages.")
uploadServiceURL := flag.String("uploadServiceURL", "http://assetstore-asset-upload-service.kyma-system.svc.cluster.local:3000", "Upload Service URL.")
insecureAssetDownload := flag.Bool("insecureAssetDownload", false, "Flag for skipping certificate verification for asset download. ")
insecureSpecDownload := flag.Bool("insecureSpecDownload", false, "Flag for skipping certificate verification for API specification download. ")

flag.Parse()

Expand All @@ -44,13 +46,14 @@ func parseArgs() *options {
detailedErrorResponse: *detailedErrorResponse,
uploadServiceURL: *uploadServiceURL,
insecureAssetDownload: *insecureAssetDownload,
insecureSpecDownload: *insecureSpecDownload,
}
}

func (o *options) String() string {
return fmt.Sprintf("--externalAPIPort=%d --proxyPort=%d --uploadServiceURL=%s"+
"--namespace=%s --requestTimeout=%d --requestLogging=%t --specRequestTimeout=%d"+
"--assetstoreRequestTimeout=%d --detailedErrorResponse=%t --insecureAssetDownload=%t",
"--assetstoreRequestTimeout=%d --detailedErrorResponse=%t --insecureAssetDownload=%t --insecureSpecDownload=%t",
o.externalAPIPort, o.proxyPort, o.uploadServiceURL,
o.namespace, o.requestTimeout, o.requestLogging, o.specRequestTimeout, o.assetstoreRequestTimeout, o.detailedErrorResponse, o.insecureAssetDownload)
o.namespace, o.requestTimeout, o.requestLogging, o.specRequestTimeout, o.assetstoreRequestTimeout, o.detailedErrorResponse, o.insecureAssetDownload, o.insecureSpecDownload)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ func TestMetadataHandler_CreateService(t *testing.T) {
Labels: &map[string]string{"showcase": "true"},
Api: &API{
TargetUrl: "http://service.com",
Credentials: &Credentials{
Oauth: &Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
ClientSecret: "clientSecret",
Credentials: &CredentialsWithCSRF{
OauthWithCSRF: &OauthWithCSRF{
Oauth: Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
ClientSecret: "clientSecret",
},
},
},
Spec: apiRawSpec,
Expand All @@ -71,7 +73,7 @@ func TestMetadataHandler_CreateService(t *testing.T) {
Labels: &map[string]string{"showcase": "true"},
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Oauth: &model.Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
Expand Down Expand Up @@ -129,10 +131,12 @@ func TestMetadataHandler_CreateService(t *testing.T) {
Labels: &map[string]string{"showcase": "true"},
Api: &API{
TargetUrl: "http://service.com",
Credentials: &Credentials{
Basic: &BasicAuth{
Username: "username",
Password: "password",
Credentials: &CredentialsWithCSRF{
BasicWithCSRF: &BasicAuthWithCSRF{
BasicAuth: BasicAuth{
Username: "username",
Password: "password",
},
},
},
Spec: apiRawSpec,
Expand All @@ -157,7 +161,7 @@ func TestMetadataHandler_CreateService(t *testing.T) {
Labels: &map[string]string{"showcase": "true"},
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Basic: &model.Basic{
Username: "username",
Password: "password",
Expand Down Expand Up @@ -214,9 +218,11 @@ func TestMetadataHandler_CreateService(t *testing.T) {
Labels: &map[string]string{"showcase": "true"},
Api: &API{
TargetUrl: "http://service.com",
Credentials: &Credentials{
CertificateGen: &CertificateGen{
CommonName: "commonName",
Credentials: &CredentialsWithCSRF{
CertificateGenWithCSRF: &CertificateGenWithCSRF{
CertificateGen: CertificateGen{
CommonName: "commonName",
},
},
},
Spec: apiRawSpec,
Expand All @@ -241,7 +247,7 @@ func TestMetadataHandler_CreateService(t *testing.T) {
Labels: &map[string]string{"showcase": "true"},
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
CertificateGen: &model.CertificateGen{
CommonName: "commonName",
},
Expand Down Expand Up @@ -434,7 +440,7 @@ func TestMetadataHandler_GetService(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Oauth: &model.Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
Expand Down Expand Up @@ -477,9 +483,9 @@ func TestMetadataHandler_GetService(t *testing.T) {
assert.Equal(t, "service provider", serviceDetails.Provider)
assert.Equal(t, "service description", serviceDetails.Description)
assert.Equal(t, "http://service.com", serviceDetails.Api.TargetUrl)
assert.Equal(t, "http://oauth.com", serviceDetails.Api.Credentials.Oauth.URL)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Oauth.ClientID)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Oauth.ClientSecret)
assert.Equal(t, "http://oauth.com", serviceDetails.Api.Credentials.OauthWithCSRF.URL)
assert.Equal(t, stars, serviceDetails.Api.Credentials.OauthWithCSRF.ClientID)
assert.Equal(t, stars, serviceDetails.Api.Credentials.OauthWithCSRF.ClientSecret)
assert.Equal(t, apiSpec, raw2Json(t, json.RawMessage(serviceDetails.Api.Spec)))
assert.Equal(t, eventsSpec, raw2Json(t, json.RawMessage(serviceDetails.Events.Spec)))
assert.Equal(t, "documentation name", serviceDetails.Documentation.DisplayName)
Expand All @@ -499,7 +505,7 @@ func TestMetadataHandler_GetService(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Basic: &model.Basic{
Username: "username",
Password: "password",
Expand Down Expand Up @@ -541,8 +547,8 @@ func TestMetadataHandler_GetService(t *testing.T) {
assert.Equal(t, "service provider", serviceDetails.Provider)
assert.Equal(t, "service description", serviceDetails.Description)
assert.Equal(t, "http://service.com", serviceDetails.Api.TargetUrl)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Basic.Username)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Basic.Password)
assert.Equal(t, stars, serviceDetails.Api.Credentials.BasicWithCSRF.Username)
assert.Equal(t, stars, serviceDetails.Api.Credentials.BasicWithCSRF.Password)
assert.Equal(t, apiSpec, raw2Json(t, serviceDetails.Api.Spec))
assert.Equal(t, eventsSpec, raw2Json(t, serviceDetails.Events.Spec))
assert.Equal(t, "documentation name", serviceDetails.Documentation.DisplayName)
Expand All @@ -562,7 +568,7 @@ func TestMetadataHandler_GetService(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
CertificateGen: &model.CertificateGen{
CommonName: "commonName",
Certificate: "test-cert",
Expand Down Expand Up @@ -604,7 +610,7 @@ func TestMetadataHandler_GetService(t *testing.T) {
assert.Equal(t, "service provider", serviceDetails.Provider)
assert.Equal(t, "service description", serviceDetails.Description)
assert.Equal(t, "http://service.com", serviceDetails.Api.TargetUrl)
assert.Equal(t, "commonName", serviceDetails.Api.Credentials.CertificateGen.CommonName)
assert.Equal(t, "commonName", serviceDetails.Api.Credentials.CertificateGenWithCSRF.CommonName)
assert.Equal(t, apiSpec, raw2Json(t, serviceDetails.Api.Spec))
assert.Equal(t, eventsSpec, raw2Json(t, serviceDetails.Events.Spec))
assert.Equal(t, "documentation name", serviceDetails.Documentation.DisplayName)
Expand All @@ -625,7 +631,7 @@ func TestMetadataHandler_GetService(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Oauth: &model.Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
Expand Down Expand Up @@ -664,9 +670,9 @@ func TestMetadataHandler_GetService(t *testing.T) {
assert.Equal(t, "service provider", serviceDetails.Provider)
assert.Equal(t, "service description", serviceDetails.Description)
assert.Equal(t, "http://service.com", serviceDetails.Api.TargetUrl)
assert.Equal(t, "http://oauth.com", serviceDetails.Api.Credentials.Oauth.URL)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Oauth.ClientID)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Oauth.ClientSecret)
assert.Equal(t, "http://oauth.com", serviceDetails.Api.Credentials.OauthWithCSRF.URL)
assert.Equal(t, stars, serviceDetails.Api.Credentials.OauthWithCSRF.ClientID)
assert.Equal(t, stars, serviceDetails.Api.Credentials.OauthWithCSRF.ClientSecret)
assert.Equal(t, apiSpec, raw2Json(t, json.RawMessage(serviceDetails.Api.Spec)))
assert.Nil(t, serviceDetails.Events)
assert.Nil(t, serviceDetails.Documentation)
Expand Down Expand Up @@ -852,7 +858,7 @@ func TestMetadataHandler_GetServices(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Oauth: &model.Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
Expand Down Expand Up @@ -891,9 +897,9 @@ func TestMetadataHandler_GetServices(t *testing.T) {
assert.Equal(t, "service provider", serviceDetails.Provider)
assert.Equal(t, "service description", serviceDetails.Description)
assert.Equal(t, "http://service.com", serviceDetails.Api.TargetUrl)
assert.Equal(t, "http://oauth.com", serviceDetails.Api.Credentials.Oauth.URL)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Oauth.ClientID)
assert.Equal(t, stars, serviceDetails.Api.Credentials.Oauth.ClientSecret)
assert.Equal(t, "http://oauth.com", serviceDetails.Api.Credentials.OauthWithCSRF.URL)
assert.Equal(t, stars, serviceDetails.Api.Credentials.OauthWithCSRF.ClientID)
assert.Equal(t, stars, serviceDetails.Api.Credentials.OauthWithCSRF.ClientSecret)
assert.Equal(t, []byte("\"non json api spec\""), []byte(serviceDetails.Api.Spec))
assert.Nil(t, serviceDetails.Events)
assert.Nil(t, serviceDetails.Documentation)
Expand All @@ -910,11 +916,13 @@ func TestMetadataHandler_UpdateService(t *testing.T) {
Description: "service description",
Api: &API{
TargetUrl: "http://service.com",
Credentials: &Credentials{
Oauth: &Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
ClientSecret: "clientSecret",
Credentials: &CredentialsWithCSRF{
OauthWithCSRF: &OauthWithCSRF{
Oauth: Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
ClientSecret: "clientSecret",
},
},
},
Spec: apiRawSpec,
Expand All @@ -936,7 +944,7 @@ func TestMetadataHandler_UpdateService(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Oauth: &model.Oauth{
URL: "http://oauth.com",
ClientID: "clientId",
Expand Down Expand Up @@ -984,9 +992,9 @@ func TestMetadataHandler_UpdateService(t *testing.T) {
assert.Equal(t, "service provider", serviceDetailsResponse.Provider)
assert.Equal(t, "service description", serviceDetailsResponse.Description)
assert.Equal(t, "http://service.com", serviceDetailsResponse.Api.TargetUrl)
assert.Equal(t, "http://oauth.com", serviceDetailsResponse.Api.Credentials.Oauth.URL)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.Oauth.ClientID)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.Oauth.ClientSecret)
assert.Equal(t, "http://oauth.com", serviceDetailsResponse.Api.Credentials.OauthWithCSRF.URL)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.OauthWithCSRF.ClientID)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.OauthWithCSRF.ClientSecret)
assert.Equal(t, apiSpec, raw2Json(t, serviceDetailsResponse.Api.Spec))
assert.Equal(t, eventsSpec, raw2Json(t, serviceDetailsResponse.Events.Spec))
assert.Equal(t, "documentation name", serviceDetailsResponse.Documentation.DisplayName)
Expand All @@ -998,18 +1006,20 @@ func TestMetadataHandler_UpdateService(t *testing.T) {
assert.Equal(t, http.StatusOK, rr.Code)
})

t.Run("should update a service with Basic Auth credentials", func(t *testing.T) {
t.Run("should update a service with BasicWithCSRF Auth credentials", func(t *testing.T) {
// given
serviceDetails := ServiceDetails{
Name: "service name",
Provider: "service provider",
Description: "service description",
Api: &API{
TargetUrl: "http://service.com",
Credentials: &Credentials{
Basic: &BasicAuth{
Username: "username",
Password: "password",
Credentials: &CredentialsWithCSRF{
BasicWithCSRF: &BasicAuthWithCSRF{
BasicAuth: BasicAuth{
Username: "username",
Password: "password",
},
},
},
Spec: apiRawSpec,
Expand All @@ -1031,7 +1041,7 @@ func TestMetadataHandler_UpdateService(t *testing.T) {
Description: "service description",
Api: &model.API{
TargetUrl: "http://service.com",
Credentials: &model.Credentials{
Credentials: &model.CredentialsWithCSRF{
Basic: &model.Basic{
Username: "username",
Password: "password",
Expand Down Expand Up @@ -1078,8 +1088,8 @@ func TestMetadataHandler_UpdateService(t *testing.T) {
assert.Equal(t, "service provider", serviceDetailsResponse.Provider)
assert.Equal(t, "service description", serviceDetailsResponse.Description)
assert.Equal(t, "http://service.com", serviceDetailsResponse.Api.TargetUrl)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.Basic.Username)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.Basic.Password)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.BasicWithCSRF.Username)
assert.Equal(t, stars, serviceDetailsResponse.Api.Credentials.BasicWithCSRF.Password)
assert.Equal(t, apiSpec, raw2Json(t, serviceDetailsResponse.Api.Spec))
assert.Equal(t, eventsSpec, raw2Json(t, serviceDetailsResponse.Events.Spec))
assert.Equal(t, "documentation name", serviceDetailsResponse.Documentation.DisplayName)
Expand Down
Loading