-
Notifications
You must be signed in to change notification settings - Fork 0
add agent and primitives #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ | |
|
|
||
| require "json" | ||
| require "open3" | ||
| require "shellwords" | ||
|
|
||
| module Vestauth | ||
| class Binary | ||
|
|
@@ -28,15 +27,62 @@ def tool_verify(http_method:, uri:, signature:, signature_input:, signature_agen | |
| run_json_command(command) | ||
| end | ||
|
|
||
| def agent_headers(http_method:, uri:, private_key:, id:) | ||
| private_jwk = serialize_json_arg(private_key, name: "private_key") | ||
|
|
||
| command = [ | ||
| @executable, | ||
| "agent", | ||
| "headers", | ||
| http_method, | ||
| uri, | ||
| "--private-jwk", | ||
| private_jwk, | ||
| "--uid", | ||
| id | ||
| ] | ||
|
|
||
| run_json_command(command) | ||
| end | ||
|
|
||
| def primitives_verify(http_method:, uri:, signature_header:, signature_input_header:, public_key:) | ||
| public_jwk = serialize_json_arg(public_key, name: "public_key") | ||
|
|
||
| command = [ | ||
| @executable, | ||
| "primitives", | ||
| "verify", | ||
| http_method, | ||
| uri, | ||
| "--signature", | ||
| signature_header, | ||
| "--signature-input", | ||
| signature_input_header, | ||
| "--public-jwk", | ||
| public_jwk | ||
| ] | ||
|
|
||
| run_json_command(command) | ||
| end | ||
|
Comment on lines
48
to
66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Given this method is part of the public API surface, it should accept either a pre-serialized JWK string/Hash or perform a more robust conversion (e.g., accept a SuggestionConsider making For example:
Sketch: public_jwk =
case public_key
when String
public_key
when Hash
JSON.generate(public_key)
else
raise Vestauth::Error, "public_key must be a JWK JSON String or a Hash"
endReply with "@CharlieHelps yes please" if you’d like me to add a commit with this suggestion. |
||
|
|
||
| private | ||
|
|
||
| def run_json_command(command_args) | ||
| command = command_args.map { |arg| Shellwords.escape(arg.to_s) }.join(" ") | ||
| stdout, stderr, status = Open3.capture3(command) | ||
| argv = command_args.map { |arg| arg.nil? ? "" : arg.to_s } | ||
| stdout, stderr, status = Open3.capture3(*argv) | ||
|
|
||
| raise Vestauth::Error, (stderr.to_s.strip.empty? ? stdout : stderr) unless status.success? | ||
|
|
||
| JSON.parse(stdout) | ||
| end | ||
|
|
||
| def serialize_json_arg(value, name:) | ||
| return value if value.is_a?(String) | ||
| return JSON.generate(value) if value.is_a?(Hash) || value.is_a?(Array) | ||
| return JSON.generate(value.to_h) if value.respond_to?(:to_h) | ||
| return JSON.generate(value.as_json) if value.respond_to?(:as_json) | ||
|
|
||
| raise ArgumentError, "#{name} must be a JSON string, Hash/Array, or object responding to #to_h" | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Vestauth | ||
| module Primitives | ||
| module_function | ||
|
|
||
| def verify(http_method:, uri:, signature_header:, signature_input_header:, public_key:) | ||
| vestauth_binary.primitives_verify( | ||
| http_method: http_method, | ||
| uri: uri, | ||
| signature_header: signature_header, | ||
| signature_input_header: signature_input_header, | ||
| public_key: public_key | ||
| ) | ||
| end | ||
|
|
||
| def vestauth_binary | ||
| Vestauth::Binary.new | ||
| end | ||
| private_class_method :vestauth_binary | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.