tpm_api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/tpm_api.rb +71 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c08193267d14bebc5b3f2b56646e666f9857ea6
|
4
|
+
data.tar.gz: e2270420567970044acdc12c108fadfdf4ccc47e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2b93f5dd134e14ad89ab4a65b5f4401ef7d4b318f40f73a9f2fa7ed94e37e12e09ef2531c780da4594ff1ff8e1b1cc7d27661ee70546c028b1866a08582e62bd
|
7
|
+
data.tar.gz: 392fa91041dfcddfab8534f4638a6c7110b48a3620eb36d7c6df6fe63fe49c8b9963dd46b9407a52633d7c9fc5d1313b945c7d79c3c1ad611c2614965ecc696c
|
data/lib/tpm_api.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require 'httparty'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'rails'
|
5
|
+
|
6
|
+
class TpmApi
|
7
|
+
include HTTParty
|
8
|
+
cattr_accessor :url, :username, :pwd, :label_private_key, :project_id
|
9
|
+
|
10
|
+
# load default setting
|
11
|
+
def self.init
|
12
|
+
# cnf = YAML.load(ERB.new(File.read("#{Rails.root}/config/tpm_api.yml")).result)[Rails.env]
|
13
|
+
cnf = YAML::load_file(File.join(Rails.root, 'config/tpm_api.yml'))
|
14
|
+
# cnf = YAML::load_file(File.join(File.dirname(__dir__), 'config/tpm_api.yml'))
|
15
|
+
self.url = cnf["url"]
|
16
|
+
self.username = cnf["username"]
|
17
|
+
self.pwd = cnf["pwd"]
|
18
|
+
self.label_private_key = cnf["label_private_key"] || "Private Key"
|
19
|
+
|
20
|
+
# find or create default project by name
|
21
|
+
project_name = cnf["project_name"] || "Tapptic's internal certificate renewal tool"
|
22
|
+
project_tags = cnf["project_tags"] || "project"
|
23
|
+
project = TpmApi.get("/projects/search/#{CGI.escape(project_name)}.json").try(:first)
|
24
|
+
|
25
|
+
if project.present?
|
26
|
+
puts "/projects/search/#{URI::encode(project_name)}.json"
|
27
|
+
self.project_id = project["id"]
|
28
|
+
else
|
29
|
+
self.project_id = TpmApi.post("/projects.json", {name: project_name, tags: project_tags})["id"]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# get method api
|
34
|
+
# url ex: "/passwords.json" => get list passwords
|
35
|
+
# options is hash data query.
|
36
|
+
def self.get(url, options = {})
|
37
|
+
HTTParty.get("#{self.url}#{url}", :headers => {'Content-Type' =>'application/json; charset=utf-8'}, :basic_auth => {:username => self.username, :password => self.pwd} )
|
38
|
+
end
|
39
|
+
|
40
|
+
# post method api
|
41
|
+
# url ex: "/passwords.json" => get list passwords
|
42
|
+
# options is hash data query. ex: TpmApi.post("/projects", {name: 'abc', tags: 'test,tool'})
|
43
|
+
def self.post(url, options = {})
|
44
|
+
HTTParty.post("#{self.url}#{url}", :body => options.to_json, :headers => {'Content-Type' =>'application/json; charset=utf-8'}, :basic_auth => {:username => self.username, :password => self.pwd})
|
45
|
+
end
|
46
|
+
|
47
|
+
# put method api
|
48
|
+
# url ex: "/passwords/ID.json" => update password with id=ID
|
49
|
+
# options is hash data query. ex: TpmApi.put("/passwords/1.json", {name: 'change name password'})
|
50
|
+
def self.put(url, options = {})
|
51
|
+
HTTParty.put("#{self.url}#{url}", :body => options.to_json, :headers => {'Content-Type' =>'application/json; charset=utf-8'}, :basic_auth => {:username => self.username, :password => self.pwd})
|
52
|
+
end
|
53
|
+
|
54
|
+
# delete method api
|
55
|
+
# url ex: "/projects/ID.json" => delete project with id=ID
|
56
|
+
def self.delete(url)
|
57
|
+
HTTParty.delete("#{self.url}#{url}", :body => options.to_json, :headers => {'Content-Type' =>'application/json; charset=utf-8'}, :basic_auth => {:username => self.username, :password => self.pwd})
|
58
|
+
end
|
59
|
+
|
60
|
+
# upload private key will call 2 api:
|
61
|
+
# 1- create password with pwd=passphrase, name=name, custom_field=content
|
62
|
+
# 2- update label_custom_field to math with config in file tpm_api.yml [label_private_key]
|
63
|
+
def self.upload_private_key(name, passphrase="", content)
|
64
|
+
new_pwd = TpmApi.post("/passwords.json", {name: name, password: passphrase, project_id: self.project_id, :custom_data1 => content})
|
65
|
+
TpmApi.put("/passwords/#{new_pwd['id']}/custom_fields.json", {:custom_label1=>self.label_private_key, :custom_type1 =>"text"})
|
66
|
+
new_pwd
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
TpmApi.init()
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tpm_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pyco
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Wrap Team password management API
|
42
|
+
email: pyco@p.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/tpm_api.rb
|
48
|
+
homepage: http://rubygems.org/gems/tpm_api
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.4.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Team password management API!
|
72
|
+
test_files: []
|