gitaly-ruby for operations that interact with multiple repositories, such as branch merging.
Overview
The Ruby client is implemented in theGitalyRemoteRepository class, which handles:
- gRPC service client creation
- Authentication with bearer tokens
- SSL/TLS certificate management
- Remote repository operations
ruby/lib/gitlab/git/gitaly_remote_repository.rb
Basic Usage
Initialization
Constructor Parameters
- gitaly_repository: A Gitaly repository protobuf message
- call: The current gRPC call context
Authentication
The Ruby client uses HMAC-based bearer tokens for authentication:Token Format
Tokens follow the format:v2.{hmac}.{timestamp}
- v2: Token version
- hmac: HMAC-SHA256 of the timestamp
- timestamp: Unix timestamp when token was issued
Request Metadata
Tokens are sent in request metadata:SSL/TLS Configuration
The client automatically handles SSL/TLS certificates:Certificate Loading
Certificates are loaded from environment variables:Environment Variables
SSL_CERT_DIR: Directory containing certificate filesSSL_CERT_FILE: Path to a single certificate file
Repository Operations
Check Branch Existence
Get Commit ID
Check if Repository Exists
Check if Repository Has Branches
Check if Repository is Empty
Address Resolution
The client normalizes Gitaly addresses:Supported Address Formats
unix:/path/to/socket- Unix domain sockettcp://hostname:port- Insecure TCPtls://hostname:port- TCP with TLS
Distributed Tracing
The client supports GitLab LabKit tracing:Creating Service Stubs
Pattern for creating gRPC service stubs:Available Services
Gitaly::RefService::Stub- Reference operationsGitaly::CommitService::Stub- Commit operationsGitaly::RepositoryService::Stub- Repository operations
Complete Example
Here’s a complete example of using the Ruby client:Configuration Requirements
Environment Variables
For TLS connections, set one or both:Dependencies
Required gems:Error Handling
Path Access Error
Remote repositories cannot be accessed by path:Certificate Errors
If SSL certificates are not configured:Best Practices
- Environment Configuration: Always set SSL certificate environment variables for TLS connections
- Error Handling: Wrap RPC calls in error handling for network failures
- Token Security: Keep shared secrets secure and rotate them regularly
- Interceptors: Enable tracing interceptors for observability
- Connection Reuse: The gRPC stub handles connection pooling automatically
API Patterns
All RPC calls follow this pattern:Client Constants
- CLIENT_NAME: Identifies this client in request metadata
- PEM_REXP: Regex for parsing PEM-encoded certificates