-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch logstream gem to use Cloud API v2 (#22)
* Update logstream gem to use Cloud API v2
- Loading branch information
Showing
9 changed files
with
133 additions
and
162 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,19 @@ | ||
FROM ubuntu:latest | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
curl \ | ||
make \ | ||
build-essential \ | ||
g++ \ | ||
libssl-dev \ | ||
ruby-dev | ||
RUN mkdir /src | ||
|
||
COPY . /src | ||
|
||
RUN cd /src \ | ||
&& gem build logstream \ | ||
&& gem install logstream-*.gem | ||
|
||
ENTRYPOINT ["/bin/bash"] |
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 was deleted.
Oops, something went wrong.
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 +1,2 @@ | ||
require 'logstream/client' | ||
require 'logstream/cloudapi_v2' |
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,60 @@ | ||
require 'net/https' | ||
require 'json' | ||
|
||
module Logstream | ||
class CloudAPIV2 | ||
class Error < StandardError; end | ||
|
||
attr_accessor :client_id, :client_secret, :endpoint | ||
CLOUDAPI_ENDPOINT = 'https://cloud.acquia.com/api' | ||
|
||
def initialize(client_id, client_secret) | ||
@client_id = client_id | ||
@client_secret = client_secret | ||
end | ||
|
||
def get(path) | ||
bearer_token = get_token | ||
uri = URI.parse("#{CLOUDAPI_ENDPOINT}#{path}") | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = true | ||
request = Net::HTTP::Get.new(uri.request_uri) | ||
request['Authorization'] = "Bearer #{bearer_token}" | ||
response = http.request(request) | ||
parsed = JSON.parse(response.body) rescue nil | ||
case response.code.to_i | ||
when 200 | ||
raise Error, "Unexpected reply #{response.body}" unless parsed | ||
parsed | ||
else | ||
raise Error, "HTTP #{response.code}: #{response.body}" | ||
end | ||
end | ||
|
||
def get_application_environments(application_uuid) | ||
response = get("/applications/#{application_uuid}/environments") #, { :query => { "filter" => "name%3D#{env}"}}) | ||
raise Error, "No Environments found." if response['total'] == 0 | ||
raise Error, "Unexpected reply #{response}" unless response['_embedded']['items'] | ||
response['_embedded']['items'] | ||
end | ||
|
||
def get_envirornment_logstream(environment_uuid) | ||
response = get("/environments/#{environment_uuid}/logstream") | ||
raise Error, "Unexpected reply #{response}" unless response['logstream'] | ||
response['logstream'] | ||
end | ||
|
||
def get_token | ||
uri = URI.parse("https://accounts.acquia.com/api/auth/oauth/token") | ||
response = Net::HTTP.post_form(uri, 'client_id' => @client_id, 'client_secret' => @client_secret, 'grant_type' => 'client_credentials') | ||
parsed = JSON.parse(response.body) rescue nil | ||
case response.code.to_i | ||
when 200 | ||
raise Error, "Unexpected reply #{response.body}" unless parsed["access_token"] | ||
parsed["access_token"] | ||
else | ||
raise Error, "HTTP #{response.code}: #{response.body}" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.