Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
571db1a2
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
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
9 deletions
+10
-9
app/services/check_gcp_project_billing_service.rb
app/services/check_gcp_project_billing_service.rb
+1
-1
app/workers/check_gcp_project_billing_worker.rb
app/workers/check_gcp_project_billing_worker.rb
+2
-2
spec/services/check_gcp_project_billing_service_spec.rb
spec/services/check_gcp_project_billing_service_spec.rb
+5
-4
spec/workers/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
class
CheckGcpProjectBillingService
def
execute
(
token
)
def
execute
(
token
)
client
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
token
,
nil
)
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
client
.
projects_get_billing_info
(
project
.
name
).
billingEnabled
end
end
end
end
...
...
app/workers/check_gcp_project_billing_worker.rb
View file @
571db1a2
...
@@ -11,9 +11,9 @@ class CheckGcpProjectBillingWorker
...
@@ -11,9 +11,9 @@ class CheckGcpProjectBillingWorker
return
unless
token
return
unless
token
return
unless
try_obtain_lease_for
(
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
|
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
end
end
...
...
spec/services/check_gcp_project_billing_service_spec.rb
View file @
571db1a2
...
@@ -2,13 +2,14 @@ require 'spec_helper'
...
@@ -2,13 +2,14 @@ require 'spec_helper'
describe
CheckGcpProjectBillingService
do
describe
CheckGcpProjectBillingService
do
let
(
:service
)
{
described_class
.
new
}
let
(
:service
)
{
described_class
.
new
}
let
(
:projects
)
{
[
double
(
name:
'first_project'
),
double
(
name:
'second_project'
)]
}
describe
'#execute'
do
describe
'#execute'
do
before
do
before
do
expect_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
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
)
.
to
receive_message_chain
(
:projects_get_billing_info
,
:billingEnabled
)
.
and_return
(
project_billing_enabled
)
.
and_return
(
project_billing_enabled
)
end
end
...
@@ -18,13 +19,13 @@ describe CheckGcpProjectBillingService do
...
@@ -18,13 +19,13 @@ describe CheckGcpProjectBillingService do
context
'google account has a billing enabled gcp project'
do
context
'google account has a billing enabled gcp project'
do
let
(
:project_billing_enabled
)
{
true
}
let
(
:project_billing_enabled
)
{
true
}
it
{
is_expected
.
to
eq
(
true
)
}
it
{
is_expected
.
to
eq
(
projects
)
}
end
end
context
'google account does not have a billing enabled gcp project'
do
context
'google account does not have a billing enabled gcp project'
do
let
(
:project_billing_enabled
)
{
false
}
let
(
:project_billing_enabled
)
{
false
}
it
{
is_expected
.
to
eq
(
false
)
}
it
{
is_expected
.
to
eq
(
[]
)
}
end
end
end
end
end
end
spec/workers/check_gcp_project_billing_worker_spec.rb
View file @
571db1a2
...
@@ -11,7 +11,7 @@ describe CheckGcpProjectBillingWorker do
...
@@ -11,7 +11,7 @@ describe CheckGcpProjectBillingWorker do
end
end
it
'calls the service'
do
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
subject
end
end
...
@@ -19,7 +19,7 @@ describe CheckGcpProjectBillingWorker do
...
@@ -19,7 +19,7 @@ describe CheckGcpProjectBillingWorker do
it
'stores billing status in redis'
do
it
'stores billing status in redis'
do
redis_double
=
double
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
(
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
)
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