Skip to content

Commit

Permalink
Merge pull request #55 from Infisical/daniel/ruby-sdk-fixes
Browse files Browse the repository at this point in the history
fix: ruby sdk extended schema
  • Loading branch information
DanielHougaard authored Oct 26, 2024
2 parents 8a82ce6 + 02bc13b commit 9cab8be
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ languages/node/examples/lambda-node/**/*
# Schemas, no reason having these on github because they're auto generated
crates/infisical-napi/**/schemas.ts
languages/*/**/schemas.*
!languages/*/**/extended_schemas/schemas.rb


.DS_Store

Expand Down
15 changes: 12 additions & 3 deletions crates/infisical/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ pub enum Error {
SecretBadRequest { message: String },

// Access token 404 error
#[error("Failed to authenticate, did you provide the correct site URL?")]
NotFoundAccessTokenRequest,
#[error("Failed to authenticate, did you provide the correct site URL?, {}", .message)]
NotFoundAccessTokenRequest { message: String },

// Access token 401 error
#[error("[Failed to authenticate]: Did you provide the correct client ID and secret?")]
Expand Down Expand Up @@ -117,7 +117,16 @@ pub async fn api_error_handler(
) -> Result<Error> {
if status == StatusCode::NOT_FOUND {
if is_auth_request {
return Err(Error::NotFoundAccessTokenRequest);
let r = res.json::<BadRequestError>().await;

match r {
Ok(r) => return Err(Error::NotFoundAccessTokenRequest { message: r.message }),
Err(_) => {
return Err(Error::NotFoundAccessTokenRequest {
message: "Unknown error".to_string(),
})
}
}
}

let s = match secret_name {
Expand Down
2 changes: 2 additions & 0 deletions languages/ruby/infisical-sdk/lib/clients/secrets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def get(
secret_name:,
project_id:,
environment:,
expand_secret_references: true,
path: nil,
include_imports: nil,
type: nil
Expand All @@ -28,6 +29,7 @@ def get(
environment: environment,
path: path,
include_imports: include_imports,
expand_secret_references: expand_secret_references,
get_secret_options_type: type
))

Expand Down
38 changes: 38 additions & 0 deletions languages/ruby/infisical-sdk/lib/extended_schemas/schemas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module InfisicalSDK
# Command mapper
class InfisicalCommands < Command
attribute :get_secret, Types.Constructor(GetSecretOptions).optional.default(nil)
attribute :list_secrets, Types.Constructor(ListSecretsOptions).optional.default(nil)
attribute :create_secret, Types.Constructor(CreateSecretOptions).optional.default(nil)
attribute :update_secret, Types.Constructor(UpdateSecretOptions).optional.default(nil)
attribute :delete_secret, Types.Constructor(DeleteSecretOptions).optional.default(nil)
attribute :create_symmetric_key, Types.Constructor(ArbitraryOptions).optional.default(nil)
attribute :encrypt_symmetric, Types.Constructor(EncryptSymmetricOptions).optional.default(nil)
attribute :decrypt_symmetric, Types.Constructor(DecryptSymmetricOptions).optional.default(nil)
attribute :universal_auth_login, Types.Constructor(UniversalAuthLoginClass).optional.default(nil)
attribute :kubernetes_auth_login, Types.Constructor(KubernetesAuthLoginClass).optional.default(nil)
attribute :azure_auth_login, Types.Constructor(AzureAuthLoginClass).optional.default(nil)
attribute :gcp_id_token_auth_login, Types.Constructor(GcpIDTokenAuthLoginClass).optional.default(nil)
attribute :gcp_iam_auth_login, Types.Constructor(GcpIamAuthLoginClass).optional.default(nil)
attribute :aws_iam_auth_login, Types.Constructor(AwsIamAuthLoginClass).optional.default(nil)

def to_dynamic
{
"getSecret" => get_secret&.to_dynamic,
"listSecrets" => list_secrets&.to_dynamic,
"createSecret" => create_secret&.to_dynamic,
"updateSecret" => update_secret&.to_dynamic,
"deleteSecret" => delete_secret&.to_dynamic,
"createSymmetricKey" => create_symmetric_key&.to_dynamic,
"encryptSymmetric" => encrypt_symmetric&.to_dynamic,
"decryptSymmetric" => decrypt_symmetric&.to_dynamic,
"universalAuthLogin" => universal_auth_login&.to_dynamic,
"kubernetesAuthLogin" => kubernetes_auth_login&.to_dynamic,
"azureAuthLogin" => azure_auth_login&.to_dynamic,
"gcpIdTokenAuthLogin" => gcp_id_token_auth_login&.to_dynamic,
"gcpIamAuthLogin" => gcp_iam_auth_login&.to_dynamic,
"awsIamAuthLogin" => aws_iam_auth_login&.to_dynamic,
}.compact
end
end
end
1 change: 1 addition & 0 deletions languages/ruby/infisical-sdk/lib/infisical-sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(site_url = nil, cache_ttl = 300)
client_secret: nil,
client_id: nil,
auth: nil,
ssl_certificate_path: nil,
user_agent: 'infisical-ruby-sdk',
cache_ttl: cache_ttl,
site_url: site_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module InfisicalSDK
project_id: String,
environment: String,
path: String?,
expand_secret_references: bool?,
include_imports: bool?,
type: String?
) -> InfisicalSecret
Expand Down

0 comments on commit 9cab8be

Please sign in to comment.