-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1360 from cloudfoundry-incubator/v3-create-servic…
…e-broker-support-additional-auths-166266507 Make POST /v3/service_brokers extensible to support different authentication types
- Loading branch information
Showing
9 changed files
with
302 additions
and
32 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,45 @@ | ||
require 'messages/base_message' | ||
require 'utils/hash_utils' | ||
|
||
module VCAP::CloudController | ||
class ServiceBrokerCreateMessage < BaseMessage | ||
register_allowed_keys [:name, :url, :credentials] | ||
ALLOWED_CREDENTIAL_TYPES = ['basic'].freeze | ||
|
||
validates_with NoAdditionalKeysValidator | ||
|
||
validates :name, string: true | ||
validates :url, string: true | ||
validates :credentials, hash: true | ||
validates_inclusion_of :credentials_type, in: ALLOWED_CREDENTIAL_TYPES, | ||
message: "credentials.type must be one of #{ALLOWED_CREDENTIAL_TYPES}" | ||
|
||
validate :validate_credentials_data | ||
|
||
def credentials_type | ||
HashUtils.dig(credentials, :type) | ||
end | ||
|
||
def credentials_data | ||
@credentials_data ||= BasicCredentialsMessage.new(HashUtils.dig(credentials, :data)) | ||
end | ||
|
||
def validate_credentials_data | ||
unless credentials_data.valid? | ||
errors.add( | ||
:credentials_data, | ||
"Field(s) #{credentials_data.errors.keys.map(&:to_s)} must be valid: #{credentials_data.errors.full_messages}" | ||
) | ||
end | ||
end | ||
|
||
class BasicCredentialsMessage < BaseMessage | ||
register_allowed_keys [:username, :password] | ||
|
||
validates_with NoAdditionalKeysValidator | ||
|
||
validates :username, string: true | ||
validates :password, string: true | ||
end | ||
end | ||
end |
69 changes: 69 additions & 0 deletions
69
docs/v3/source/includes/experimental_resources/service_brokers/_create.md.erb
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,69 @@ | ||
### Create a service broker | ||
|
||
``` | ||
Example Request | ||
``` | ||
|
||
```shell | ||
curl "https://api.example.org/v3/service_brokers" \ | ||
-X POST \ | ||
-H "Authorization: bearer [token]" \ | ||
-H "Content-type: application/json" \ | ||
-d '{ | ||
"name": "my_service_broker", | ||
"url": "https://example.service-broker.com", | ||
"credentials": { | ||
"type": "basic", | ||
"data": { | ||
"username": "us3rn4me", | ||
"password": "p4ssw0rd" | ||
} | ||
}, | ||
"relationships": { | ||
"space": { | ||
"data": { | ||
"guid": "2f35885d-0c9d-4423-83ad-fd05066f8576" | ||
} | ||
} | ||
} | ||
}' | ||
``` | ||
|
||
``` | ||
Example Response | ||
``` | ||
|
||
```http | ||
HTTP/1.1 201 Created | ||
Content-Type: application/json | ||
|
||
<%= yield_content :single_service_broker %> | ||
``` | ||
|
||
This endpoint creates a new service broker. | ||
|
||
#### Definition | ||
`POST /v3/service_brokers` | ||
|
||
#### Required Parameters | ||
|
||
Name | Type | Description | ||
---- | ---- | ----------- | ||
**name** | _string_ | Name of the service broker. | ||
**url** | _string_ | URL of the service broker. | ||
**credentials** | [_credentials_](#the-credentials-object) | Credentials used to authenticate against the service broker. | ||
|
||
#### Optional Parameters | ||
|
||
Name | Type | Description | Default | ||
---- | ---- | ----------- | ------- | ||
**space** | [_to-one relationship_](#to-one-relationships) | If set, restricts broker visibility to the specified space. | `null` | ||
|
||
<%= yield_content :service_broker_credentials_object %> | ||
|
||
#### Permitted Roles | ||
| | ||
--- | --- | ||
Space Developer | | ||
Admin | | ||
|
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,5 @@ | ||
$LOAD_PATH.push(File.expand_path(File.join(__dir__, '..', 'app'))) | ||
$LOAD_PATH.push(File.expand_path(File.join(__dir__, '..', 'lib'))) | ||
|
||
# So that specs using this helper don't fail with undefined constant error | ||
module VCAP; end |
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
Oops, something went wrong.