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.
Maintain un-processed usage event records
Allow consumer_guid to be passed into request for AppUsageEvent and ServiceUsageEvent records. This establishes a consumer of these events. Un-processed consumer records will be maintained by cloud controller. Registered consumers are automatically deleted if associated event is removed.
- Loading branch information
1 parent
8395537
commit 3faa80c
Showing
18 changed files
with
420 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module VCAP::CloudController | ||
class AppUsageConsumerAccess < BaseAccess | ||
def create?(_object, _params=nil) | ||
admin_user? | ||
end | ||
|
||
def read?(object) | ||
return @ok_read if instance_variable_defined?(:@ok_read) | ||
|
||
@ok_read = admin_user? || admin_read_only_user? || global_auditor? || object_is_visible_to_user?(object, context.user) | ||
end | ||
|
||
def read_for_update?(_object, _params=nil) | ||
admin_user? | ||
end | ||
|
||
def can_remove_related_object?(object, params=nil) | ||
read_for_update?(object, params) | ||
end | ||
|
||
def read_related_object_for_update?(object, params=nil) | ||
read_for_update?(object, params) | ||
end | ||
|
||
def update?(_object, _params=nil) | ||
admin_user? | ||
end | ||
|
||
def delete?(_object) | ||
admin_user? | ||
end | ||
|
||
# These methods should be called first to determine if the user's token has the appropriate scope for the operation | ||
|
||
def read_with_token?(_) | ||
admin_user? || admin_read_only_user? || has_read_scope? || global_auditor? | ||
end | ||
|
||
def create_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def read_for_update_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def can_remove_related_object_with_token?(*) | ||
read_for_update_with_token?(*) | ||
end | ||
|
||
def read_related_object_for_update_with_token?(*) | ||
read_for_update_with_token?(*) | ||
end | ||
|
||
def update_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def delete_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def index_with_token?(_) | ||
admin_user? || admin_read_only_user? | ||
end | ||
|
||
def index?(_object_class, _params=nil) | ||
admin_user? || admin_read_only_user? | ||
end | ||
|
||
def reset?(_object_class) | ||
admin_user? | ||
end | ||
|
||
def reset_with_token?(_object_class) | ||
admin_user? | ||
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,79 @@ | ||
module VCAP::CloudController | ||
class ServiceUsageConsumerAccess < BaseAccess | ||
def create?(_object, _params=nil) | ||
admin_user? | ||
end | ||
|
||
def read?(object) | ||
return @ok_read if instance_variable_defined?(:@ok_read) | ||
|
||
@ok_read = admin_user? || admin_read_only_user? || global_auditor? || object_is_visible_to_user?(object, context.user) | ||
end | ||
|
||
def read_for_update?(_object, _params=nil) | ||
admin_user? | ||
end | ||
|
||
def can_remove_related_object?(object, params=nil) | ||
read_for_update?(object, params) | ||
end | ||
|
||
def read_related_object_for_update?(object, params=nil) | ||
read_for_update?(object, params) | ||
end | ||
|
||
def update?(_object, _params=nil) | ||
admin_user? | ||
end | ||
|
||
def delete?(_object) | ||
admin_user? | ||
end | ||
|
||
# These methods should be called first to determine if the user's token has the appropriate scope for the operation | ||
|
||
def read_with_token?(_) | ||
admin_user? || admin_read_only_user? || has_read_scope? || global_auditor? | ||
end | ||
|
||
def create_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def read_for_update_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def can_remove_related_object_with_token?(*) | ||
read_for_update_with_token?(*) | ||
end | ||
|
||
def read_related_object_for_update_with_token?(*) | ||
read_for_update_with_token?(*) | ||
end | ||
|
||
def update_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def delete_with_token?(_) | ||
admin_user? || has_write_scope? | ||
end | ||
|
||
def index_with_token?(_) | ||
admin_user? || admin_read_only_user? | ||
end | ||
|
||
def index?(_object_class, _params=nil) | ||
admin_user? || admin_read_only_user? | ||
end | ||
|
||
def reset?(_object_class) | ||
admin_user? | ||
end | ||
|
||
def reset_with_token?(_object_class) | ||
admin_user? | ||
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
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,26 @@ | ||
module VCAP::CloudController | ||
class AppUsageConsumer < Sequel::Model | ||
plugin :validation_helpers | ||
|
||
many_to_one :last_processed_event, | ||
class: 'VCAP::CloudController::AppUsageEvent', | ||
key: :last_processed_guid, | ||
primary_key: :guid | ||
|
||
def validate | ||
validates_presence %i[consumer_guid last_processed_guid] | ||
validates_unique :consumer_guid | ||
validates_max_length 255, :consumer_guid, message: 'must be less than 255 characters' | ||
end | ||
|
||
def last_processed_guid=(guid) | ||
self[:last_processed_guid] = guid | ||
end | ||
|
||
def last_processed_guid | ||
self[:last_processed_guid] | ||
end | ||
|
||
export_attributes :consumer_guid, :last_processed_guid | ||
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,26 @@ | ||
module VCAP::CloudController | ||
class ServiceUsageConsumer < Sequel::Model | ||
plugin :validation_helpers | ||
|
||
many_to_one :last_processed_event, | ||
class: 'VCAP::CloudController::ServiceUsageEvent', | ||
key: :last_processed_guid, | ||
primary_key: :guid | ||
|
||
def validate | ||
validates_presence %i[consumer_guid last_processed_guid] | ||
validates_unique :consumer_guid | ||
validates_max_length 255, :consumer_guid, message: 'must be less than 255 characters' | ||
end | ||
|
||
def last_processed_guid=(guid) | ||
self[:last_processed_guid] = guid | ||
end | ||
|
||
def last_processed_guid | ||
self[:last_processed_guid] | ||
end | ||
|
||
export_attributes :consumer_guid, :last_processed_guid | ||
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
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,9 @@ | ||
Sequel.migration do | ||
change do | ||
create_table :app_usage_consumers do |_t| | ||
VCAP::Migration.common(self) | ||
String :consumer_guid, null: false, size: 255 | ||
String :last_processed_guid, null: false, size: 255 | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
db/migrations/20241218113511_create_service_usage_consumers.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Sequel.migration do | ||
change do | ||
create_table :service_usage_consumers do |_t| | ||
VCAP::Migration.common(self) | ||
String :consumer_guid, null: false, size: 255 | ||
String :last_processed_guid, null: false, size: 255 | ||
end | ||
end | ||
end |
Oops, something went wrong.