-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instance binding parameters 🚧 WIP 🚧 (#558)
* parameters * adding more tests * test description change * tests fix * typo * fixes after code review * revert * reverting capital letters back, because tests are failing * trigger tests * update unit test * fix test * after reformating * fix for test * after code review * go convention to use lower case in errors * remove FDescribe: * after refview * after reformating
- Loading branch information
Showing
10 changed files
with
433 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package osb | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Peripli/service-manager/pkg/client" | ||
"github.com/Peripli/service-manager/pkg/log" | ||
"github.com/Peripli/service-manager/pkg/types" | ||
"github.com/Peripli/service-manager/pkg/util" | ||
"net" | ||
"net/http" | ||
) | ||
|
||
func Get(doRequestWithClient util.DoRequestWithClientFunc, brokerAPIVersion string, ctx context.Context, broker *types.ServiceBroker, url string, resourceType string) ([]byte, error) { | ||
|
||
log.C(ctx).Debugf("attempting to fetch %s from URL %s and broker with name %s", resourceType, url, broker.Name) | ||
brokerClient, err := client.NewBrokerClient(broker, doRequestWithClient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
response, err := brokerClient.SendRequest(ctx, http.MethodGet, url, | ||
map[string]string{}, nil, map[string]string{ | ||
brokerAPIVersionHeader: brokerAPIVersion, | ||
}) | ||
if err != nil { | ||
log.C(ctx).WithError(err).Errorf("error while forwarding request to service broker %s", broker.Name) | ||
return nil, &util.HTTPError{ | ||
ErrorType: "ServiceBrokerErr", | ||
Description: fmt.Sprintf("could not reach service broker %s at %s", broker.Name, broker.BrokerURL), | ||
StatusCode: http.StatusBadGateway, | ||
} | ||
} | ||
|
||
if response.StatusCode != http.StatusOK { | ||
log.C(ctx).WithError(err).Errorf("error fetching %s from URL %s and broker with name %s: %s", resourceType, url, broker.Name, util.HandleResponseError(response)) | ||
return nil, &util.HTTPError{ | ||
ErrorType: "ServiceBrokerErr", | ||
Description: fmt.Sprintf("error fetching %s from URL %s and broker with name %s: %s", resourceType, url, broker.Name, response.Status), | ||
StatusCode: http.StatusBadRequest, | ||
} | ||
} | ||
|
||
var responseBytes []byte | ||
if responseBytes, err = util.BodyToBytes(response.Body); err != nil { | ||
if nErr, ok := err.(net.Error); ok && nErr.Timeout() { | ||
log.C(ctx).WithError(err).Errorf("error fetching %s from URL %s and broker with name %s: %s: time out", resourceType, url, broker.Name, err) | ||
return nil, &util.HTTPError{ | ||
ErrorType: "ServiceBrokerErr", | ||
Description: fmt.Sprintf("error fetching %s from URL %s and broker with name %s: timed out", resourceType, url, broker.Name), | ||
StatusCode: http.StatusGatewayTimeout, | ||
} | ||
} | ||
return nil, fmt.Errorf("error getting content from body of response from %s with status %s: %s", url, response.Status, err) | ||
} | ||
|
||
log.C(ctx).Debugf("successfully fetched %s from URL %s and broker with name %s", resourceType, url, broker.Name) | ||
|
||
return responseBytes, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
"github.com/Peripli/service-manager/pkg/query" | ||
"github.com/Peripli/service-manager/pkg/types" | ||
"github.com/Peripli/service-manager/pkg/util" | ||
) | ||
|
||
func GetServiceOfferingByServiceInstanceId(repository Repository, ctx context.Context, serviceInstanceId string) (*types.ServiceOffering, error) { | ||
byID := query.ByField(query.EqualsOperator, "id", serviceInstanceId) | ||
criteria := query.CriteriaForContext(ctx) | ||
obj, err := repository.Get(ctx, types.ServiceInstanceType, append(criteria, byID)...) | ||
if err != nil { | ||
return nil, util.HandleStorageError(err, types.ServiceInstanceType.String()) | ||
} | ||
serviceInstance := obj.(*types.ServiceInstance) | ||
planObject, err := repository.Get(ctx, types.ServicePlanType, query.ByField(query.EqualsOperator, "id", serviceInstance.ServicePlanID)) | ||
if err != nil { | ||
return nil, util.HandleStorageError(err, types.ServicePlanType.String()) | ||
} | ||
plan := planObject.(*types.ServicePlan) | ||
serviceObject, err := repository.Get(ctx, types.ServiceOfferingType, query.ByField(query.EqualsOperator, "id", plan.ServiceOfferingID)) | ||
if err != nil { | ||
return nil, util.HandleStorageError(err, types.ServiceOfferingType.String()) | ||
} | ||
service := serviceObject.(*types.ServiceOffering) | ||
return service, nil | ||
} |
Oops, something went wrong.