Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
fix after CR#2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasiak committed Apr 24, 2020
1 parent b751d3f commit 08fafc6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion components/kyma-environment-broker/cmd/broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func main() {
inputFactory, err := input.NewInputBuilderFactory(optComponentsSvc, runtimeProvider, cfg.Provisioning, cfg.KymaVersion)
fatalOnError(err)

edpClient := edp.CreateEDPAdminClient(cfg.EDP, logs)
edpClient := edp.NewClient(cfg.EDP, logs)

avsDel := avs.NewDelegator(cfg.Avs, db.Operations())
externalEvalAssistant := avs.NewExternalEvalAssistant(cfg.Avs)
Expand Down
32 changes: 28 additions & 4 deletions components/kyma-environment-broker/internal/edp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package edp

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"

kebError "github.com/kyma-incubator/compass/components/kyma-environment-broker/internal/error"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2/clientcredentials"
)

const (
Expand All @@ -21,18 +24,39 @@ const (

dataTenantTmpl = "%s/namespaces/%s/dataTenants"
metadataTenantTmpl = "%s/namespaces/%s/dataTenants/%s/%s/metadata"

namespaceToken = "%s/oauth2/token"
)

type Config struct {
AuthURL string
AdminURL string
Namespace string
Secret string
Environment string `envconfig:"default=prod"`
Required bool `envconfig:"default=false"`
Disabled bool
}

type Client struct {
config Config
httpClient *http.Client
log logrus.FieldLogger
}

func NewClient(config Config, httpClient *http.Client, log logrus.FieldLogger) *Client {
func NewClient(config Config, log logrus.FieldLogger) *Client {
cfg := clientcredentials.Config{
ClientID: fmt.Sprintf("edp-namespace;%s", config.Namespace),
ClientSecret: config.Secret,
TokenURL: fmt.Sprintf(namespaceToken, config.AuthURL),
Scopes: []string{"edp-namespace.read edp-namespace.update"},
}
httpClientOAuth := cfg.Client(context.Background())
httpClientOAuth.Timeout = 30 * time.Second

return &Client{
config: config,
httpClient: httpClient,
httpClient: httpClientOAuth,
log: log,
}
}
Expand Down Expand Up @@ -93,7 +117,7 @@ func (c *Client) DeleteMetadataTenant(name, env, key string) error {
return c.processResponse(response)
}

func (c *Client) GetMetadataTenant(name, env string) ([]MetadataItem, error) {
func (c *Client) GetMetadataTenant(name, env string) (_ []MetadataItem, err error) {
response, err := c.httpClient.Get(c.metadataTenantURL(name, env))
if err != nil {
return []MetadataItem{}, errors.Wrap(err, "while requesting about dataTenant metadata")
Expand All @@ -111,7 +135,7 @@ func (c *Client) GetMetadataTenant(name, env string) ([]MetadataItem, error) {
return metadata, nil
}

func (c *Client) post(URL string, data []byte) error {
func (c *Client) post(URL string, data []byte) (err error) {
response, err := c.httpClient.Post(URL, "application/json", bytes.NewBuffer(data))
if err != nil {
return errors.Wrapf(err, "while sending POST request on %s", URL)
Expand Down
37 changes: 0 additions & 37 deletions components/kyma-environment-broker/internal/edp/client_builder.go

This file was deleted.

17 changes: 13 additions & 4 deletions components/kyma-environment-broker/internal/edp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestClient_CreateDataTenant(t *testing.T) {
AdminURL: testServer.URL,
Namespace: testNamespace,
}
client := NewClient(config, testServer.Client(), logger.NewLogDummy())
client := NewClient(config, logger.NewLogDummy())
client.setHttpClient(testServer.Client())

// when
err := client.CreateDataTenant(DataTenantPayload{
Expand Down Expand Up @@ -59,7 +60,8 @@ func TestClient_DeleteDataTenant(t *testing.T) {
AdminURL: testServer.URL,
Namespace: testNamespace,
}
client := NewClient(config, testServer.Client(), logger.NewLogDummy())
client := NewClient(config, logger.NewLogDummy())
client.setHttpClient(testServer.Client())

err := client.CreateDataTenant(DataTenantPayload{
Name: subAccountID,
Expand Down Expand Up @@ -87,7 +89,8 @@ func TestClient_CreateMetadataTenant(t *testing.T) {
AdminURL: testServer.URL,
Namespace: testNamespace,
}
client := NewClient(config, testServer.Client(), logger.NewLogDummy())
client := NewClient(config, logger.NewLogDummy())
client.setHttpClient(testServer.Client())

// when
err := client.CreateMetadataTenant(subAccountID, environment, MetadataTenantPayload{Key: "tK", Value: "tV"})
Expand All @@ -114,7 +117,8 @@ func TestClient_DeleteMetadataTenant(t *testing.T) {
AdminURL: testServer.URL,
Namespace: testNamespace,
}
client := NewClient(config, testServer.Client(), logger.NewLogDummy())
client := NewClient(config, logger.NewLogDummy())
client.setHttpClient(testServer.Client())

err := client.CreateMetadataTenant(subAccountID, environment, MetadataTenantPayload{Key: key, Value: "tV"})
assert.NoError(t, err)
Expand Down Expand Up @@ -334,3 +338,8 @@ func (s *server) getDataTenants(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(http.StatusOK)
}

// setHttpClient auxiliary method of testing to get rid of oAuth client wrapper
func (c *Client) setHttpClient(httpClient *http.Client) {
c.httpClient = httpClient
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The provisioning process contains the following steps:
| Resolve_Target_Secret | Hyperscaler Account Pool | Provides the name of a Gardener Secret that contains Hypescaler account credentials used during cluster provisioning. | @koala7659 |
| AVS_Configuration_Step | AvS | Sets up external and internal monitoring of Kyma Runtime. | @abbi-guarav |
| Create_LMS_Tenant | LMS | Requests a tenant in the LMS system or provides a tenant ID if it was created before. | @piotrmiskiewicz |
| EDP_Registration | Event Data Platform | Registers a SKR on Event Data Platform with the necessary parameters. This step is not required and can be disabled. | @jasiu001 |
| Provision Azure Event Hubs | Event Hub | Creates the Azure Event Hub Namespace which is a managed Kafka cluster for a Kyma Runtime. | @anishj0shi |
| Overrides_From_Secrets_And_Config_Step | Kyma overrides | Configures default overrides for Kyma. | @jasiu001 |
| ServiceManagerOverrides | Service Manager | Configures overrides with Service Manager credentials. | @mszostok |
Expand All @@ -35,6 +36,7 @@ The deprovisioning process contains the following steps:
|------------------------------|----------------|-------------|----------------------------------------------------------------------------------------|-----------|
| Deprovision_Initialization | Deprovisioning | Done | Initialize the `DeprovisioningOperation` instance with data fetched from the `ProvisioningOperation`. | @jasiu001 |
| Deprovision Azure Event Hubs | Event Hub | In progress | Deletes the Azure Event Hub Namespace. | @montaro |
| EDP_Deregistration | Event Data Platform | Done | Removes all entries about SKR from Event Data Platform. | @jasiu001 |
| Remove_Runtime | Deprovisioning | Done | Triggers deprovisioning of a Runtime in the Runtime Provisioner. | @jasiu001 |


Expand Down

0 comments on commit 08fafc6

Please sign in to comment.