Class: PritunlApiClient::Key
- Inherits:
-
Object
- Object
- PritunlApiClient::Key
- Defined in:
- lib/pritunl_api_client/key.rb
Overview
Interact with /key api’s
Instance Method Summary collapse
-
#download(organization_id:, user_id:, path: nil) ⇒ String
deprecated
Deprecated.
This method of downloading the OVPN file is not reliable. Use #download_tar or #download_zip instead.
-
#download_chromebook_profile(organization_id:, user_id:, path: nil) ⇒ String
Download a users onc key (Chromebook profile) as a zip archive.
-
#download_tar(organization_id:, user_id:, path: nil) ⇒ String
Download a users key tar archive.
-
#download_zip(organization_id:, user_id:, path: nil) ⇒ String
Download a users key zip archive.
-
#initialize(api) ⇒ Key
constructor
A new instance of Key.
-
#temporary_url(organization_id:, user_id:) ⇒ Hash
Generate a temporary url to download a users key archive.
Constructor Details
#initialize(api) ⇒ Key
Returns a new instance of Key.
7 8 9 |
# File 'lib/pritunl_api_client/key.rb', line 7 def initialize( api ) @api = api end |
Instance Method Details
#download(organization_id:, user_id:, path: nil) ⇒ String
This method of downloading the OVPN file is not reliable. Use #download_tar or #download_zip instead.
User organization must be attached to a server AND user must be enabled and NOT connected!
Download a users key
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pritunl_api_client/key.rb', line 20 def download( organization_id:, user_id:, path: nil ) temporary_url_id = temporary_url( organization_id: organization_id, user_id: user_id )['id'] all_users = @api.get( "/user/#{organization_id}" ) user = all_users.find { |user| user['id'] == user_id } fail StandardError, 'Could not find user!' unless user servers = user['servers'] fail StandardError, 'Could not find servers attached to user!' unless servers && servers.count >= 1 server_id = servers.first['id'] data = @api.get( "/key/#{temporary_url_id}/#{server_id}.key" ) return data unless path File.write( path, data.force_encoding( 'utf-8' ) ) path end |
#download_chromebook_profile(organization_id:, user_id:, path: nil) ⇒ String
Download a users onc key (Chromebook profile) as a zip archive
66 67 68 69 70 71 |
# File 'lib/pritunl_api_client/key.rb', line 66 def download_chromebook_profile( organization_id:, user_id:, path: nil ) data = @api.get( "/key_onc/#{organization_id}/#{user_id}.zip" ) return data unless path File.write( path, data.force_encoding( 'utf-8' ) ) path end |
#download_tar(organization_id:, user_id:, path: nil) ⇒ String
Download a users key tar archive
40 41 42 43 44 45 |
# File 'lib/pritunl_api_client/key.rb', line 40 def download_tar( organization_id:, user_id:, path: nil ) data = @api.get( "/key/#{organization_id}/#{user_id}.tar" ) return data unless path File.write( path, data.force_encoding( 'utf-8' ) ) path end |
#download_zip(organization_id:, user_id:, path: nil) ⇒ String
Download a users key zip archive
53 54 55 56 57 58 |
# File 'lib/pritunl_api_client/key.rb', line 53 def download_zip( organization_id:, user_id:, path: nil ) data = @api.get( "/key/#{organization_id}/#{user_id}.zip" ) return data unless path File.write( path, data.force_encoding( 'utf-8' ) ) path end |
#temporary_url(organization_id:, user_id:) ⇒ Hash
Generate a temporary url to download a users key archive
78 79 80 |
# File 'lib/pritunl_api_client/key.rb', line 78 def temporary_url( organization_id:, user_id: ) @api.get( "/key/#{organization_id}/#{user_id}" ) end |