Skip to content

Commit

Permalink
Add support for org secrets (#1655)
Browse files Browse the repository at this point in the history
* Add methods for Org Actions Secrets

* Add methods for Org Codespaces Secrets

* Add methods for Org Dependabot Secrets
  • Loading branch information
kamarcum committed Jan 5, 2024
1 parent cf9b2af commit 7317615
Show file tree
Hide file tree
Showing 33 changed files with 10,971 additions and 0 deletions.
49 changes: 49 additions & 0 deletions lib/octokit/client/actions_secrets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def get_actions_public_key(repo)
get "#{Repository.path repo}/actions/secrets/public-key"
end

# Get public key for secrets encryption
#
# @param org [String] A GitHub organization
# @return [Hash] key_id and key
# @see https://developer.github.com/v3/actions/secrets/#get-your-public-key
def get_org_actions_public_key(org)
get "#{Organization.path org}/actions/secrets/public-key"
end

# List secrets
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -26,6 +35,17 @@ def list_actions_secrets(repo)
end
end

# List org secrets
#
# @param org [String] A GitHub organization
# @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
# @see https://developer.github.com/v3/actions/secrets/#list-organization-secrets
def list_org_actions_secrets(org)
paginate "#{Organization.path org}/actions/secrets" do |data, last_response|
data.secrets.concat last_response.data.secrets
end
end

# Get a secret
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -36,6 +56,16 @@ def get_actions_secret(repo, name)
get "#{Repository.path repo}/actions/secrets/#{name}"
end

# Get an org secret
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @return [Hash] name, created_at and updated_at
# @see https://developer.github.com/v3/actions/secrets/#get-a-secret
def get_org_actions_secret(org, name)
get "#{Organization.path org}/actions/secrets/#{name}"
end

# Create or update secrets
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -46,6 +76,16 @@ def create_or_update_actions_secret(repo, name, options)
put "#{Repository.path repo}/actions/secrets/#{name}", options
end

# Create or update org secrets
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @param options [Hash] encrypted_value and key_id
# @see https://developer.github.com/v3/actions/secrets/#create-or-update-a-secret
def create_or_update_org_actions_secret(org, name, options)
put "#{Organization.path org}/actions/secrets/#{name}", options
end

# Delete a secret
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -55,6 +95,15 @@ def delete_actions_secret(repo, name)
boolean_from_response :delete, "#{Repository.path repo}/actions/secrets/#{name}"
end

# Delete an org secret
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @see https://developer.github.com/v3/actions/secrets/#delete-a-secret
def delete_org_actions_secret(org, name)
boolean_from_response :delete, "#{Organization.path org}/actions/secrets/#{name}"
end

# Get environment public key for secrets encryption
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand Down
49 changes: 49 additions & 0 deletions lib/octokit/client/codespaces_secrets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def get_codespaces_public_key(repo)
get "#{Repository.path repo}/codespaces/secrets/public-key"
end

# Get public key for secrets encryption
#
# @param org [String] A GitHub organization
# @return [Hash] key_id and key
# @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#get-an-organization-public-key
def get_org_codespaces_public_key(org)
get "#{Organization.path org}/codespaces/secrets/public-key"
end

# List secrets
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -26,6 +35,17 @@ def list_codespaces_secrets(repo)
end
end

# List org secrets
#
# @param org [String] A GitHub organization
# @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
# @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#list-organization-secrets
def list_org_codespaces_secrets(org)
paginate "#{Organization.path org}/codespaces/secrets" do |data, last_response|
data.secrets.concat last_response.data.secrets
end
end

# Get a secret
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -36,6 +56,16 @@ def get_codespaces_secret(repo, name)
get "#{Repository.path repo}/codespaces/secrets/#{name}"
end

# Get an org secret
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @return [Hash] name, created_at, updated_at, and visibility
# @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#get-an-organization-secret
def get_org_codespaces_secret(org, name)
get "#{Organization.path org}/codespaces/secrets/#{name}"
end

# Create or update secrets
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -46,6 +76,16 @@ def create_or_update_codespaces_secret(repo, name, options)
put "#{Repository.path repo}/codespaces/secrets/#{name}", options
end

# Create or update org secrets
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @param options [Hash] encrypted_value and key_id
# @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
def create_or_update_org_codespaces_secret(org, name, options)
put "#{Organization.path org}/codespaces/secrets/#{name}", options
end

# Delete a secret
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -54,6 +94,15 @@ def create_or_update_codespaces_secret(repo, name, options)
def delete_codespaces_secret(repo, name)
boolean_from_response :delete, "#{Repository.path repo}/codespaces/secrets/#{name}"
end

# Delete an org secret
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @see https://docs.github.com/en/rest/codespaces/organization-secrets?apiVersion=2022-11-28#delete-an-organization-secret
def delete_org_codespaces_secret(org, name)
boolean_from_response :delete, "#{Organization.path org}/codespaces/secrets/#{name}"
end
end
end
end
49 changes: 49 additions & 0 deletions lib/octokit/client/dependabot_secrets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def get_dependabot_public_key(repo)
get "#{Repository.path repo}/dependabot/secrets/public-key"
end

# Get public key for secrets encryption
#
# @param org [String] A GitHub organization
# @return [Hash] key_id and key
# @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#get-an-organization-public-key
def get_org_dependabot_public_key(org)
get "#{Organization.path org}/dependabot/secrets/public-key"
end

# List secrets
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -26,6 +35,17 @@ def list_dependabot_secrets(repo)
end
end

# List org secrets
#
# @param org [String] A GitHub organization
# @return [Hash] total_count and list of secrets (each item is hash with name, created_at and updated_at)
# @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#list-organization-secrets
def list_org_dependabot_secrets(org)
paginate "#{Organization.path org}/dependabot/secrets" do |data, last_response|
data.secrets.concat last_response.data.secrets
end
end

# Get a secret
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -36,6 +56,16 @@ def get_dependabot_secret(repo, name)
get "#{Repository.path repo}/dependabot/secrets/#{name}"
end

# Get an org secret
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @return [Hash] name, created_at, updated_at, and visibility
# @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#get-an-organization-secret
def get_org_dependabot_secret(org, name)
get "#{Organization.path org}/dependabot/secrets/#{name}"
end

# Create or update secrets
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -46,6 +76,16 @@ def create_or_update_dependabot_secret(repo, name, options)
put "#{Repository.path repo}/dependabot/secrets/#{name}", options
end

# Create or update org secrets
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @param options [Hash] encrypted_value and key_id
# @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
def create_or_update_org_dependabot_secret(org, name, options)
put "#{Organization.path org}/dependabot/secrets/#{name}", options
end

# Delete a secret
#
# @param repo [Integer, String, Hash, Repository] A GitHub repository
Expand All @@ -54,6 +94,15 @@ def create_or_update_dependabot_secret(repo, name, options)
def delete_dependabot_secret(repo, name)
boolean_from_response :delete, "#{Repository.path repo}/dependabot/secrets/#{name}"
end

# Delete an org secret
#
# @param org [String] A GitHub organization
# @param name [String] Name of secret
# @see https://docs.github.com/en/rest/dependabot/organization-secrets?apiVersion=2022-11-28#delete-an-organization-secret
def delete_org_dependabot_secret(org, name)
boolean_from_response :delete, "#{Organization.path org}/dependabot/secrets/#{name}"
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"http_interactions": [
{
"request": {
"method": "get",
"uri": "https://api.github.com/orgs/<GITHUB_TEST_ORGANIZATION>/actions/secrets/public-key",
"body": {
"encoding": "US-ASCII",
"base64_string": ""
},
"headers": {
"Accept": [
"application/vnd.github.v3+json"
],
"User-Agent": [
"Octokit Ruby Gem 8.0.0"
],
"Content-Type": [
"application/json"
],
"Authorization": [
"token <<ACCESS_TOKEN>>"
],
"Accept-Encoding": [
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"Server": [
"GitHub.com"
],
"Date": [
"Tue, 12 Dec 2023 21:53:47 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Transfer-Encoding": [
"chunked"
],
"Cache-Control": [
"private, max-age=60, s-maxage=60"
],
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"Etag": [
"W/\"aa41a98fa5415fc5a3e22c00ea9be5c5d60b20bac3cf4fcecbf1b751180b3347\""
],
"X-Oauth-Scopes": [
"admin:org, repo"
],
"X-Accepted-Oauth-Scopes": [
"admin:org"
],
"Github-Authentication-Token-Expiration": [
"2023-12-19 21:50:28 UTC"
],
"X-Github-Media-Type": [
"github.v3; format=json"
],
"X-Github-Api-Version-Selected": [
"2022-11-28"
],
"X-Ratelimit-Limit": [
"5000"
],
"X-Ratelimit-Remaining": [
"4989"
],
"X-Ratelimit-Reset": [
"1702418555"
],
"X-Ratelimit-Used": [
"11"
],
"X-Ratelimit-Resource": [
"core"
],
"Access-Control-Expose-Headers": [
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset"
],
"Access-Control-Allow-Origin": [
"*"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubdomains; preload"
],
"X-Frame-Options": [
"deny"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Xss-Protection": [
"0"
],
"Referrer-Policy": [
"origin-when-cross-origin, strict-origin-when-cross-origin"
],
"Content-Security-Policy": [
"default-src 'none'"
],
"X-Github-Request-Id": [
"C796:323D:92063D:970C7C:6578D66B"
]
},
"body": {
"encoding": "ASCII-8BIT",
"base64_string": "eyJrZXlfaWQiOiI1NjgyNTAxNjcyNDI1NDk3NDMiLCJrZXkiOiJPSkU3Q1dq\nOEFPZVY1cUVaeUVnck1oZ1RGTjlaK3FPNzlmUUN4cmJiUkZFPSJ9\n"
}
},
"recorded_at": "Tue, 12 Dec 2023 21:53:47 GMT"
}
],
"recorded_with": "VCR 6.2.0"
}

0 comments on commit 7317615

Please sign in to comment.