pub struct Jira { /* private fields */ }Expand description
Jira API client with session management capabilities.
This client handles authentication, session caching, and issue retrieval
from Jira instances. It implements the Session trait for automatic
credential management and retry logic.
ยงThread Safety
The client is not thread-safe due to mutable retry state. Each thread should use its own client instance for concurrent operations.
ยงSession Lifecycle
- Initialization: Client created with configuration
- Authentication: Credentials prompted when first needed
- Session Caching: Successful sessions stored for reuse
- Automatic Retry: Expired sessions trigger re-authentication
- Error Handling: Persistent failures return empty results
Implementationsยง
Sourceยงimpl Jira
impl Jira
Sourcepub fn new(config: &JiraConfig) -> Self
pub fn new(config: &JiraConfig) -> Self
Creates a new Jira API client instance.
Initializes the HTTP client with default settings suitable for Jira API interactions. The client is configured for JSON requests and includes appropriate timeout and connection settings.
ยงArguments
config- Configuration containing Jira URL and login information
ยงExamples
use kasl::api::{Jira, JiraConfig};
let config = JiraConfig {
login: "username".to_string(),
api_url: "https://jira.company.com".to_string(),
};
let jira = Jira::new(&config);Sourcepub async fn get_completed_issues(
&mut self,
date: &NaiveDate,
) -> Result<Vec<JiraIssue>>
pub async fn get_completed_issues( &mut self, date: &NaiveDate, ) -> Result<Vec<JiraIssue>>
Retrieves all issues completed by the current user on a specific date.
This method performs a sophisticated issue search using JQL (Jira Query Language) to find issues that were marked as completed on the specified date. The search includes robust error handling and automatic session management with retry logic.
ยงJQL Query Details
The search uses the following criteria:
- Status Filter: Issues with status โDoneโ or โะ ะตัะตะฝะฐโ (supports localized Jira)
- Resolution Date: Issues resolved within the full day range (00:00 to 23:59)
- Assignee Filter: Only issues assigned to the current user (
currentUser())
ยงSession Management
The method implements sophisticated session handling:
- Session Retrieval: Get or create a valid session token using the Session trait
- API Request: Execute the JQL search with session cookie authentication
- Error Handling: Detect HTTP 401 (Unauthorized) responses indicating expired sessions
- Automatic Retry: Clear cached session and retry authentication up to the limit
- Graceful Degradation: Return empty results on persistent authentication failures
ยงError Recovery Strategy
Unlike other API integrations, Jira errors are allowed to propagate rather than returning empty results silently. This is because Jira data is typically more critical for work tracking, and users should be aware of connection issues.
However, authentication failures are handled gracefully with automatic retry logic and eventual fallback to empty results after exhausting retries.
ยงDate Handling
The method formats the provided date to ensure proper JQL syntax and covers the entire day from midnight to 23:59 to capture all possible resolution times within the target date.
ยงArguments
date- The date to search for completed issues (in any timezone)
ยงReturns
Returns a vector of JiraIssue objects representing completed work.
Returns an empty vector if:
- No issues are found matching the criteria
- Authentication fails persistently after all retries
- Network errors occur during the request
ยงErrors
May return errors for:
- JSON parsing failures in API responses
- Unexpected HTTP response formats
- Session token formatting errors
Network errors and authentication failures are handled gracefully and result in empty results rather than propagated errors.
ยงExamples
let config = JiraConfig {
login: "username".to_string(),
api_url: "https://jira.company.com".to_string(),
};
let mut jira = Jira::new(&config);
let today = chrono::Local::now().date_naive();
let issues = jira.get_completed_issues(&today).await?;
for issue in issues {
println!("Completed: {} - {}", issue.key, issue.fields.summary);
}Trait Implementationsยง
Sourceยงimpl Session for Jira
impl Session for Jira
Sourceยงasync fn login(&self) -> Result<String>
async fn login(&self) -> Result<String>
Performs session-based authentication with Jira.
This method implements Jiraโs session authentication flow using the REST API. It sends user credentials to the authentication endpoint and receives a session cookie that can be used for subsequent requests.
ยงAuthentication Process
- Credential Validation: Ensures credentials are set before proceeding
- HTTP Request: POST to the session authentication endpoint with JSON credentials
- Response Validation: Checks for successful HTTP status codes
- Cookie Extraction: Parses session information from the response
- Format Preparation: Creates properly formatted cookie string for headers
ยงSession Cookie Format
The returned session ID is formatted as {cookie_name}={cookie_value} and
should be included in the Cookie header of subsequent API requests.
ยงReturns
Returns a formatted session cookie string on successful authentication.
ยงErrors
Returns an error if:
- No credentials have been set (programming error)
- HTTP request fails due to network issues
- Credentials are invalid (401 response)
- Jira returns an unexpected response format
- Session parsing fails
Sourceยงfn set_credentials(&mut self, password: &str) -> Result<()>
fn set_credentials(&mut self, password: &str) -> Result<()>
Sets user credentials for Jira authentication.
Stores the provided username and password in memory for use during the authentication process. This method is called by the session management system when credentials are needed.
ยงSecurity Notes
- Credentials are only stored in memory temporarily
- Password is stored in plain text for authentication
- No persistence to disk or configuration files
- Credentials are cleared after successful authentication
ยงArguments
password- The userโs Jira password in plain text
ยงReturns
Always returns Ok(()) as this operation cannot fail.
Sourceยงfn session_id_file(&self) -> &str
fn session_id_file(&self) -> &str
Returns the filename for storing Jira session tokens.
The session file is stored in the userโs application data directory and contains the cached session token for automatic login restoration.
Sourceยงfn secret(&self) -> Secret
fn secret(&self) -> Secret
Returns a configured Secret instance for secure password prompting.
The Secret manager handles secure password input with hidden characters and optional encrypted caching in the userโs data directory.
ยงReturns
A configured Secret instance with Jira-specific prompts and file names.
Sourceยงfn retry(&self) -> i32
fn retry(&self) -> i32
Returns the current authentication retry count.
Used by the session management system to track failed authentication attempts and implement retry limits.
Sourceยงfn inc_retry(&mut self)
fn inc_retry(&mut self)
Increments the authentication retry counter.
Called after each failed authentication attempt to track progress toward the maximum retry limit defined in the session management system.
Sourceยงfn reset_retry(&mut self)
fn reset_retry(&mut self)
Resets the authentication retry counter to zero.
Called after successful authentication to ensure future session requests start with a clean slate.