Skip to content

Commit

Permalink
Add gRPC endpoint (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelaossa authored Oct 9, 2024
1 parent 70bb3d2 commit 38a6e7b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Commands:
aptible endpoints:database:create DATABASE # Create a Database Endpoint
aptible endpoints:database:modify --database DATABASE ENDPOINT_HOSTNAME # Modify a Database Endpoint
aptible endpoints:deprovision [--app APP | --database DATABASE] ENDPOINT_HOSTNAME # Deprovision an App or Database Endpoint
aptible endpoints:grpc:create [--app APP] SERVICE # Create an App gRPC Endpoint
aptible endpoints:grpc:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App gRPC Endpoint
aptible endpoints:https:create [--app APP] SERVICE # Create an App HTTPS Endpoint
aptible endpoints:https:modify [--app APP] ENDPOINT_HOSTNAME # Modify an App HTTPS Endpoint
aptible endpoints:list [--app APP | --database DATABASE] # List Endpoints for an App or Database
Expand Down
30 changes: 30 additions & 0 deletions lib/aptible/cli/subcommands/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ def self.included(thor)
modify_app_vhost(tls_modify_flags, options, hostname)
end

grpc_create_flags = Helpers::Vhost::OptionSetBuilder.new do
app!
create!
port!
tls!
end

desc 'endpoints:grpc:create [--app APP] SERVICE',
'Create an App gRPC Endpoint'
grpc_create_flags.declare_options(self)
define_method 'endpoints:grpc:create' do |type|
create_app_vhost(
grpc_create_flags, options, type,
type: 'grpc', platform: 'elb'
)
end

grpc_modify_flags = Helpers::Vhost::OptionSetBuilder.new do
app!
port!
tls!
end

desc 'endpoints:grpc:modify [--app APP] ENDPOINT_HOSTNAME',
'Modify an App gRPC Endpoint'
grpc_modify_flags.declare_options(self)
define_method 'endpoints:grpc:modify' do |hostname|
modify_app_vhost(grpc_modify_flags, options, hostname)
end

https_create_flags = Helpers::Vhost::OptionSetBuilder.new do
app!
create!
Expand Down
38 changes: 38 additions & 0 deletions spec/aptible/cli/subcommands/endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,30 @@ def stub_options(**opts)
end
end

describe 'endpoints:grpc:create' do
m = 'endpoints:grpc:create'
include_examples 'shared create app vhost examples', m
include_examples 'shared create tls vhost examples', m

it 'creates a gRPC Endpoint' do
expect_create_vhost(
service,
type: 'grpc',
platform: 'elb',
internal: false,
default: false,
ip_whitelist: []
)
subject.send(m, 'web')
end

it 'creates an Endpoint with a container Port' do
expect_create_vhost(service, container_port: 10)
stub_options(port: 10)
subject.send(m, 'web')
end
end

shared_examples 'shared modify app vhost examples' do |m|
it 'does not change anything if no options are passed' do
v = Fabricate(:vhost, service: service)
Expand Down Expand Up @@ -579,6 +603,20 @@ def stub_options(**opts)
end
end

describe 'endpoints:grpc:modify' do
m = 'endpoints:grpc:modify'
include_examples 'shared modify app vhost examples', m
include_examples 'shared modify tls vhost examples', m

it 'allows updating the Container Port' do
v = Fabricate(:vhost, service: service)
expect_modify_vhost(v, container_port: 10)

stub_options(port: 10)
subject.send(m, v.external_host)
end
end

describe 'endpoints:list' do
it 'lists Endpoints across services' do
s1 = Fabricate(:service, app: app)
Expand Down

0 comments on commit 38a6e7b

Please sign in to comment.