BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
571db1a2
Unverified
Commit
571db1a2
authored
Jan 05, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return list of billing enabled projects
parent
17853757
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
9 deletions
+10
-9
check_gcp_project_billing_service.rb
app/services/check_gcp_project_billing_service.rb
+1
-1
check_gcp_project_billing_worker.rb
app/workers/check_gcp_project_billing_worker.rb
+2
-2
check_gcp_project_billing_service_spec.rb
spec/services/check_gcp_project_billing_service_spec.rb
+5
-4
check_gcp_project_billing_worker_spec.rb
spec/workers/check_gcp_project_billing_worker_spec.rb
+2
-2
No files found.
app/services/check_gcp_project_billing_service.rb
View file @
571db1a2
class
CheckGcpProjectBillingService
def
execute
(
token
)
client
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
token
,
nil
)
client
.
projects_list
.
any?
do
|
project
|
client
.
projects_list
.
select
do
|
project
|
client
.
projects_get_billing_info
(
project
.
name
).
billingEnabled
end
end
...
...
app/workers/check_gcp_project_billing_worker.rb
View file @
571db1a2
...
...
@@ -11,9 +11,9 @@ class CheckGcpProjectBillingWorker
return
unless
token
return
unless
try_obtain_lease_for
(
token
)
billing_enabled
=
CheckGcpProjectBillingService
.
new
.
execute
(
token
)
billing_enabled
_projects
=
CheckGcpProjectBillingService
.
new
.
execute
(
token
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
set
(
self
.
class
.
redis_shared_state_key_for
(
token
),
billing_enabled
)
redis
.
set
(
self
.
class
.
redis_shared_state_key_for
(
token
),
!
billing_enabled_projects
.
empty?
)
end
end
...
...
spec/services/check_gcp_project_billing_service_spec.rb
View file @
571db1a2
...
...
@@ -2,13 +2,14 @@ require 'spec_helper'
describe
CheckGcpProjectBillingService
do
let
(
:service
)
{
described_class
.
new
}
let
(
:projects
)
{
[
double
(
name:
'first_project'
),
double
(
name:
'second_project'
)]
}
describe
'#execute'
do
before
do
expect_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:projects_list
).
and_return
(
[
double
(
name:
'project_name'
)]
)
.
to
receive
(
:projects_list
).
and_return
(
projects
)
expect
_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
allow
_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive_message_chain
(
:projects_get_billing_info
,
:billingEnabled
)
.
and_return
(
project_billing_enabled
)
end
...
...
@@ -18,13 +19,13 @@ describe CheckGcpProjectBillingService do
context
'google account has a billing enabled gcp project'
do
let
(
:project_billing_enabled
)
{
true
}
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
projects
)
}
end
context
'google account does not have a billing enabled gcp project'
do
let
(
:project_billing_enabled
)
{
false
}
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
[]
)
}
end
end
end
spec/workers/check_gcp_project_billing_worker_spec.rb
View file @
571db1a2
...
...
@@ -11,7 +11,7 @@ describe CheckGcpProjectBillingWorker do
end
it
'calls the service'
do
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
)
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
)
.
and_return
([
double
])
subject
end
...
...
@@ -19,7 +19,7 @@ describe CheckGcpProjectBillingWorker do
it
'stores billing status in redis'
do
redis_double
=
double
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
).
and_return
(
true
)
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
).
and_return
(
[
double
]
)
expect
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
expect
(
redis_double
).
to
receive
(
:set
).
with
(
described_class
.
redis_shared_state_key_for
(
token
),
anything
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment