Class: SecretHub::GitHubClient
- Inherits:
-
Object
- Object
- SecretHub::GitHubClient
- Includes:
- HTTParty, Sodium
- Defined in:
- lib/secret_hub/github_client.rb
Instance Method Summary collapse
-
#delete_org_secret(org, name) ⇒ Object
DELETE /orgs/:org/actions/secrets/:secret_name.
-
#delete_secret(repo, name) ⇒ Object
DELETE /repos/:owner/:repo/actions/secrets/:name.
-
#initialize ⇒ GitHubClient
constructor
A new instance of GitHubClient.
-
#org_secrets(org) ⇒ Object
GET /orgs/:org/actions/secrets.
-
#public_key(repo_or_org) ⇒ Object
GET /repos/:owner/:repo/actions/secrets/public-key GET /orgs/:org/actions/secrets/public-key.
-
#put_org_secret(org, name, value) ⇒ Object
PUT /orgs/:org/actions/secrets/:secret_name.
-
#put_secret(repo, name, value) ⇒ Object
PUT /repos/:owner/:repo/actions/secrets/:name.
-
#secrets(repo) ⇒ Object
GET /repos/:owner/:repo/actions/secrets.
Methods included from Sodium
Constructor Details
#initialize ⇒ GitHubClient
Returns a new instance of GitHubClient.
9 10 11 |
# File 'lib/secret_hub/github_client.rb', line 9 def initialize self.class.base_uri ENV['SECRET_HUB_API_BASE'] || 'https://api.github.com' end |
Instance Method Details
#delete_org_secret(org, name) ⇒ Object
DELETE /orgs/:org/actions/secrets/:secret_name
62 63 64 |
# File 'lib/secret_hub/github_client.rb', line 62 def delete_org_secret(org, name) delete "/orgs/#{org}/actions/secrets/#{name}" end |
#delete_secret(repo, name) ⇒ Object
DELETE /repos/:owner/:repo/actions/secrets/:name
57 58 59 |
# File 'lib/secret_hub/github_client.rb', line 57 def delete_secret(repo, name) delete "/repos/#{repo}/actions/secrets/#{name}" end |
#org_secrets(org) ⇒ Object
GET /orgs/:org/actions/secrets
32 33 34 35 |
# File 'lib/secret_hub/github_client.rb', line 32 def org_secrets(org) response = get "/orgs/#{org}/actions/secrets" response['secrets'].map { |s| s['name'] } end |
#public_key(repo_or_org) ⇒ Object
GET /repos/:owner/:repo/actions/secrets/public-key GET /orgs/:org/actions/secrets/public-key
15 16 17 18 19 20 21 22 23 |
# File 'lib/secret_hub/github_client.rb', line 15 def public_key(repo_or_org) if repo_or_org.include? '/' repo = repo_or_org public_keys[repo_or_org] ||= get("/repos/#{repo}/actions/secrets/public-key") else org = repo_or_org public_keys[repo_or_org] ||= get("/orgs/#{org}/actions/secrets/public-key") end end |
#put_org_secret(org, name, value) ⇒ Object
PUT /orgs/:org/actions/secrets/:secret_name
47 48 49 50 51 52 53 54 |
# File 'lib/secret_hub/github_client.rb', line 47 def put_org_secret(org, name, value) secret = encrypt_for org, value key_id = public_key(org)['key_id'] put "/orgs/#{org}/actions/secrets/#{name}", encrypted_value: secret, key_id: key_id, visibility: 'private' end |
#put_secret(repo, name, value) ⇒ Object
PUT /repos/:owner/:repo/actions/secrets/:name
38 39 40 41 42 43 44 |
# File 'lib/secret_hub/github_client.rb', line 38 def put_secret(repo, name, value) secret = encrypt_for repo, value key_id = public_key(repo)['key_id'] put "/repos/#{repo}/actions/secrets/#{name}", encrypted_value: secret, key_id: key_id end |
#secrets(repo) ⇒ Object
GET /repos/:owner/:repo/actions/secrets
26 27 28 29 |
# File 'lib/secret_hub/github_client.rb', line 26 def secrets(repo) response = get "/repos/#{repo}/actions/secrets" response['secrets'].map { |s| s['name'] } end |