forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v3(services): Return list of service credential bindings (cloudfoundr…
…y#1761) * v3(services): Return list of service credential bindings [#173171550](https://www.pivotaltracker.com/story/show/173171550)
- Loading branch information
Brian Butz
authored
Jul 29, 2020
1 parent
214fda4
commit 3b6ccfc
Showing
18 changed files
with
429 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--color | ||
--order rand | ||
-I app |
56 changes: 36 additions & 20 deletions
56
app/controllers/v3/service_credential_bindings_controller.rb
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 |
---|---|---|
@@ -1,49 +1,65 @@ | ||
require 'fetchers/service_credential_binding_fetcher' | ||
require 'fetchers/service_credential_binding_list_fetcher' | ||
require 'presenters/v3/service_credential_binding_presenter' | ||
|
||
class ServiceCredentialBindingsController < ApplicationController | ||
before_action :ensure_service_credential_binding_exists! | ||
before_action :ensure_user_has_access! | ||
def index | ||
results = list_fetcher.fetch(space_guids: space_guids) | ||
|
||
presenter = Presenters::V3::PaginatedListPresenter.new( | ||
presenter: Presenters::V3::ServiceCredentialBindingPresenter, | ||
paginated_result: SequelPaginator.new.get_page(results, pagination_options), | ||
path: '/v3' + service_credential_bindings_path | ||
) | ||
|
||
render status: :ok, json: presenter | ||
end | ||
|
||
def show | ||
ensure_service_credential_binding_is_accessible! | ||
render status: :ok, json: serialized | ||
end | ||
|
||
private | ||
|
||
def serialized | ||
{ | ||
guid: service_credential_binding.guid, | ||
type: service_credential_binding.type | ||
} | ||
def service_credential_binding | ||
@service_credential_binding ||= fetcher.fetch(hashed_params[:guid], space_guids: space_guids) | ||
end | ||
|
||
def ensure_service_credential_binding_exists! | ||
not_found! unless service_credential_binding_exists? | ||
def space_guids | ||
if permission_queryer.can_read_globally? | ||
:all | ||
else | ||
permission_queryer.readable_space_guids | ||
end | ||
end | ||
|
||
def ensure_user_has_access! | ||
not_found! unless allowed_to_access_space? | ||
def pagination_options | ||
query_params_with_order_by = query_params.reverse_merge(order_by: :created_at) | ||
ListMessage.from_params(query_params_with_order_by, []).pagination_options | ||
end | ||
|
||
def not_found! | ||
resource_not_found!(:service_credential_binding) | ||
def serialized | ||
Presenters::V3::ServiceCredentialBindingPresenter.new(service_credential_binding).to_hash | ||
end | ||
|
||
def service_credential_binding | ||
@service_credential_binding ||= fetcher.fetch(hashed_params[:guid]) | ||
def ensure_service_credential_binding_is_accessible! | ||
not_found! unless service_credential_binding_exists? | ||
end | ||
|
||
def fetcher | ||
@fetcher ||= VCAP::CloudController::ServiceCredentialBindingFetcher.new | ||
def not_found! | ||
resource_not_found!(:service_credential_binding) | ||
end | ||
|
||
def service_credential_binding_exists? | ||
!!service_credential_binding | ||
end | ||
|
||
def allowed_to_access_space? | ||
space = service_credential_binding.space | ||
def list_fetcher | ||
@list_fetcher ||= VCAP::CloudController::ServiceCredentialBindingListFetcher.new | ||
end | ||
|
||
permission_queryer.can_read_from_space?(space.guid, space.organization_guid) | ||
def fetcher | ||
@fetcher ||= VCAP::CloudController::ServiceCredentialBindingFetcher.new | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,22 @@ | ||
module VCAP | ||
module CloudController | ||
class ServiceCredentialBindingFetcher | ||
ServiceInstanceCredential = Struct.new(:guid, :type, :space).freeze | ||
ServiceInstanceCredential = Struct.new(:guid, :type).freeze | ||
|
||
def fetch(guid) | ||
ServiceCredentialBinding::View.first(guid: guid).try do |db_binding| | ||
def fetch(guid, space_guids:) | ||
list_fetcher.fetch(space_guids: space_guids).first(guid: guid).try do |db_binding| | ||
ServiceInstanceCredential.new( | ||
db_binding.guid, | ||
db_binding.type, | ||
db_binding.space | ||
db_binding.type | ||
) | ||
end | ||
end | ||
|
||
private | ||
|
||
def list_fetcher | ||
ServiceCredentialBindingListFetcher.new | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module VCAP | ||
module CloudController | ||
class ServiceCredentialBindingListFetcher | ||
def fetch(space_guids:) | ||
case space_guids | ||
when :all | ||
ServiceCredentialBinding::View.dataset | ||
else | ||
ServiceCredentialBinding::View.where { Sequel[:space_guid] =~ space_guids } | ||
end | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
module VCAP::CloudController | ||
module Presenters | ||
module Censorship | ||
PRIVATE_DATA_HIDDEN = '[PRIVATE DATA HIDDEN]'.freeze | ||
PRIVATE_DATA_HIDDEN_LIST = '[PRIVATE DATA HIDDEN IN LISTS]'.freeze | ||
REDACTED = '[REDACTED]'.freeze | ||
REDACTED_CREDENTIAL = '***'.freeze | ||
module VCAP | ||
module CloudController | ||
module Presenters | ||
module Censorship | ||
PRIVATE_DATA_HIDDEN = '[PRIVATE DATA HIDDEN]'.freeze | ||
PRIVATE_DATA_HIDDEN_LIST = '[PRIVATE DATA HIDDEN IN LISTS]'.freeze | ||
REDACTED = '[REDACTED]'.freeze | ||
REDACTED_CREDENTIAL = '***'.freeze | ||
end | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require_relative 'base_presenter' | ||
|
||
module VCAP | ||
module CloudController | ||
module Presenters | ||
module V3 | ||
class ServiceCredentialBindingPresenter < BasePresenter | ||
def to_hash | ||
{ | ||
guid: @resource.guid, | ||
type: @resource.type | ||
} | ||
end | ||
end | ||
end | ||
end | ||
end | ||
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
42 changes: 42 additions & 0 deletions
42
docs/v3/source/includes/api_resources/_service_credential_bindings.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,42 @@ | ||
<% content_for :single_service_credential_binding_app do %> | ||
{ | ||
"guid": "ddd7fb26-c42d-4acf-a035-60fdd094a167", | ||
"type": "app" | ||
} | ||
<% end %> | ||
|
||
<% content_for :single_service_credential_binding_key do %> | ||
{ | ||
"guid": "ddd7fb26-c42d-4acf-a035-60fdd094a167", | ||
"type": "key" | ||
} | ||
<% end %> | ||
|
||
<% content_for :paginated_list_of_service_credential_bindings do |base_url| %> | ||
{ | ||
"pagination": { | ||
"total_results": 3, | ||
"total_pages": 2, | ||
"first": { | ||
"href": "https://api.example.org<%= base_url %>?page=1&per_page=2" | ||
}, | ||
"last": { | ||
"href": "https://api.example.org<%= base_url %>?page=2&per_page=2" | ||
}, | ||
"next": { | ||
"href": "https://api.example.org<%= base_url %>?page=2&per_page=2" | ||
}, | ||
"previous": null | ||
}, | ||
"resources": [ | ||
{ | ||
"guid": "dde5ad2a-d8f4-44dc-a56f-0452d744f1c3", | ||
"type": "app" | ||
}, | ||
{ | ||
"guid": "7aa37bad-6ccb-4ef9-ba48-9ce3a91b2b62", | ||
"type": "key" | ||
} | ||
] | ||
} | ||
<% end %> |
50 changes: 50 additions & 0 deletions
50
docs/v3/source/includes/experimental_resources/service_credential_bindings/_get.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,50 @@ | ||
### Get a service credential binding | ||
|
||
``` | ||
Example Request | ||
``` | ||
|
||
```shell | ||
curl "https://api.example.org/v3/service_credential_bindings/[guid]" \ | ||
-X GET \ | ||
-H "Authorization: bearer [token]" | ||
``` | ||
|
||
``` | ||
Example App Credential Binding Response | ||
``` | ||
|
||
```http | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
<%= yield_content :single_service_credential_binding_app %> | ||
``` | ||
|
||
``` | ||
Example Key Credential Binding Response | ||
``` | ||
|
||
```http | ||
HTTP/1.1 200 OK | ||
Content-Type: application/json | ||
|
||
<%= yield_content :single_service_credential_binding_key %> | ||
``` | ||
|
||
|
||
This endpoint retrieves the service credential binding by GUID. | ||
|
||
#### Definition | ||
`GET /v3/service_service_credential_bindings/:guid` | ||
|
||
#### Permitted roles | ||
| | ||
--- | --- | ||
Admin | | ||
Admin Read-Only | | ||
Global Auditor | | ||
Org Manager | | ||
Space Auditor | | ||
Space Developer | | ||
Space Manager | |
3 changes: 3 additions & 0 deletions
3
...3/source/includes/experimental_resources/service_credential_bindings/_header.md
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,3 @@ | ||
## Service Credential Binding (experimental) | ||
|
||
An instantiation of a service credential binding. |
Oops, something went wrong.