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

Refactor Application Gateway to expose authorisation related code #4563

Merged
merged 11 commits into from
Jul 5, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"sync"
"time"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/internal/authorization"
"github.com/kyma-project/kyma/components/application-gateway/internal/csrf"
csrfClient "github.com/kyma-project/kyma/components/application-gateway/internal/csrf/client"
csrfStrategy "github.com/kyma-project/kyma/components/application-gateway/internal/csrf/strategy"
"github.com/kyma-project/kyma/components/application-gateway/internal/externalapi"
"github.com/kyma-project/kyma/components/application-gateway/internal/httptools"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/applications"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/secrets"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/serviceapi"
"github.com/kyma-project/kyma/components/application-gateway/internal/proxy"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/authorization"
"github.com/kyma-project/kyma/components/application-gateway/pkg/httptools"
"github.com/kyma-project/kyma/components/application-operator/pkg/client/clientset/versioned"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -84,8 +84,8 @@ func newInternalHandler(serviceDefinitionService metadata.ServiceDefinitionServi
if serviceDefinitionService != nil {

authStrategyFactory := newAuthenticationStrategyFactory(options.proxyTimeout)
csrfClient := newCSRFClient(options.proxyTimeout)
csrfTokenStrategyFactory := csrfStrategy.NewTokenStrategyFactory(csrfClient)
csrfCl := newCSRFClient(options.proxyTimeout)
csrfTokenStrategyFactory := csrfStrategy.NewTokenStrategyFactory(csrfCl)

proxyConfig := proxy.Config{
SkipVerify: options.skipVerify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"strings"
"time"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/internal/authorization"
"github.com/kyma-project/kyma/components/application-gateway/internal/csrf"
"github.com/kyma-project/kyma/components/application-gateway/internal/httpconsts"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/authorization"
"github.com/kyma-project/kyma/components/application-gateway/pkg/httpconsts"
log "github.com/sirupsen/logrus"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import (
"strings"
"testing"

"github.com/kyma-project/kyma/components/application-gateway/internal/authorization"
"github.com/kyma-project/kyma/components/application-gateway/internal/authorization/testconsts"
"github.com/kyma-project/kyma/components/application-gateway/internal/csrf"
"github.com/kyma-project/kyma/components/application-gateway/internal/httpconsts"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/model"
"github.com/kyma-project/kyma/components/application-gateway/pkg/authorization"
"github.com/kyma-project/kyma/components/application-gateway/pkg/authorization/testconsts"
"github.com/kyma-project/kyma/components/application-gateway/pkg/httpconsts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -39,7 +38,7 @@ func TestClient_GetTokenEndpointResponse(t *testing.T) {

sf := authorization.NewStrategyFactory(authorization.FactoryConfiguration{OAuthClientTimeout: timeoutDuration})

strategy := sf.Create(&model.Credentials{BasicAuth: &model.BasicAuth{
strategy := sf.Create(&authorization.Credentials{BasicAuth: &authorization.BasicAuth{
Username: testUsername,
Password: testPassword,
}})
Expand Down Expand Up @@ -125,7 +124,7 @@ func TestAddAuthorization(t *testing.T) {
t.Run("Should update request with authorization headers in case of basicAuth strategy", func(t *testing.T) {

// given
strategy := sf.Create(&model.Credentials{BasicAuth: &model.BasicAuth{
strategy := sf.Create(&authorization.Credentials{BasicAuth: &authorization.BasicAuth{
Username: testUsername,
Password: testPassword,
}})
Expand All @@ -145,7 +144,7 @@ func TestAddAuthorization(t *testing.T) {
t.Run("Should update httpClient with transport in case of certificateGen strategy", func(t *testing.T) {

// given
strategy := sf.Create(&model.Credentials{CertificateGen: &model.CertificateGen{
strategy := sf.Create(&authorization.Credentials{CertificateGen: &authorization.CertificateGen{
CommonName: "",
PrivateKey: privateKey,
Certificate: certificate,
Expand Down
4 changes: 2 additions & 2 deletions components/application-gateway/internal/csrf/mocks/Client.go

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

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

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

6 changes: 3 additions & 3 deletions components/application-gateway/internal/csrf/strategy/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"net/http"

"github.com/kyma-project/kyma/components/application-gateway/internal/csrf"
"github.com/kyma-project/kyma/components/application-gateway/internal/httpconsts"
"github.com/kyma-project/kyma/components/application-gateway/pkg/httpconsts"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/internal/authorization"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/authorization"
log "github.com/sirupsen/logrus"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"net/http"
"testing"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
authmocks "github.com/kyma-project/kyma/components/application-gateway/internal/authorization/mocks"
"github.com/kyma-project/kyma/components/application-gateway/internal/csrf"
"github.com/kyma-project/kyma/components/application-gateway/internal/csrf/mocks"
"github.com/kyma-project/kyma/components/application-gateway/internal/httpconsts"

"github.com/kyma-project/kyma/components/application-gateway/internal/csrf"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
authmocks "github.com/kyma-project/kyma/components/application-gateway/pkg/authorization/mocks"
"github.com/kyma-project/kyma/components/application-gateway/pkg/httpconsts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
4 changes: 2 additions & 2 deletions components/application-gateway/internal/csrf/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package csrf
import (
"net/http"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/internal/authorization"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/authorization"
)

//CSRF Client is an HTTP client responsible for fetching and caching CSRF Tokens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"net/http"

"github.com/kyma-project/kyma/components/application-gateway/internal/httpconsts"
"github.com/kyma-project/kyma/components/application-gateway/internal/httperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/httpconsts"
)

type ErrorHandler struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package httperrors
import (
"net/http"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
)

type ErrorResponse struct {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package applications
import (
"fmt"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1"
log "github.com/sirupsen/logrus"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package applications_test
import (
"testing"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/applications"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/applications/mocks"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/kyma-project/kyma/components/application-operator/pkg/apis/applicationconnector/v1alpha1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down

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

56 changes: 4 additions & 52 deletions components/application-gateway/internal/metadata/model/model.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package model

import "github.com/kyma-project/kyma/components/application-gateway/pkg/authorization"

// ServiceDefinition is an internal representation of a service.
type ServiceDefinition struct {
// ID of service
Expand All @@ -23,61 +25,11 @@ type API struct {
// TargetUrl points to API.
TargetUrl string
// Credentials is a credentials of API.
Credentials *Credentials
Credentials *authorization.Credentials
// Spec contains specification of an API.
Spec []byte
// RequestParameters will be used with request send by the Application Gateway
RequestParameters *RequestParameters
}

// RequestParameters contains Headers and QueryParameters
type RequestParameters struct {
Headers *map[string][]string `json:"headers,omitempty"`
QueryParameters *map[string][]string `json:"queryParameters,omitempty"`
}

// Credentials contains OAuth or BasicAuth configuration.
type Credentials struct {
// OAuth is OAuth configuration.
OAuth *OAuth
// BasicAuth is BasicAuth configuration.
BasicAuth *BasicAuth
// CertificateGen is CertificateGen configuration.
CertificateGen *CertificateGen
// CSRFTokenEndpointURL (optional) to fetch CSRF token
CSRFTokenEndpointURL string
// Headers that are injected by the gateway
Headers *map[string][]string
// QueryParameters that are injected by the gateway
QueryParameters *map[string][]string
}

// BasicAuth contains details of BasicAuth Auth configuration
type BasicAuth struct {
// Username to use for authentication
Username string
// Password to use for authentication
Password string
}

// OAuth contains details of OAuth configuration
type OAuth struct {
// URL to OAuth token provider.
URL string
// ClientID to use for authorization.
ClientID string
// ClientSecret to use for authorization.
ClientSecret string
}

// CertificateGen details of CertificateGen configuration
type CertificateGen struct {
// CommonName of the certificate
CommonName string
// Certificate generated by Application Registry
Certificate []byte
// PrivateKey generated by Application Registry
PrivateKey []byte
RequestParameters *authorization.RequestParameters
}

// Events contains specification for events.
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package secrets

import (
"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
log "github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"errors"
"testing"

"github.com/kyma-project/kyma/components/application-gateway/internal/apperrors"
"github.com/kyma-project/kyma/components/application-gateway/internal/k8sconsts"
"github.com/kyma-project/kyma/components/application-gateway/internal/metadata/secrets/mocks"
"github.com/kyma-project/kyma/components/application-gateway/pkg/apperrors"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down

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

Loading