Skip to content

Commit

Permalink
Add ssl & proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
keepcosmos committed Jan 14, 2017
1 parent bd1cbf5 commit e545b77
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
terjira (0.2.10)
terjira (0.3.0)
activesupport (= 4.0.13)
jira-ruby (~> 1.1.3)
thor (~> 0.19.0)
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ or check OSX 10.11 issue [#12](https://github.com/keepcosmos/terjira/issues/12)
```
Authentication:
jira login # Login your Jira
# [--ssl-config] with ssl configuration
# [--proxy-config] with proxy configuration
jira logout # Logout your Jira
Project:
Expand All @@ -53,13 +55,15 @@ Sprint:
jira sprint ( ls | list ) # List of all sprint from the board
jira sprint [SPRINT_ID] # Show the sprint
jira sprint active # Show active sprints and issues
# To show issues on the sprint(include no assignee)
                                    # pass `--assignee ALL` or `-a ALL`.
Issue:
jira issue help [COMMAND] # Describe one specific subcommand
jira issue ( ls | list ) # List of issues
# default assignee option is current loggined user
# To show issues of all users(include no assignee)
                                    # pass `--assignee ALL` option.
                                    # pass `--assignee ALL` or `-a ALL`.
jira issue jql "[QUERY]" # Search issues with JQL
# ex)
# jira issue jql "project = 'TEST' AND summary ~ 'authentication'"
Expand All @@ -76,15 +80,15 @@ Issue:
```

## Todo

## Feature Todo
**Contributions are welcome!**
- [x] Add JQL command for find issues
- [x] Search issues by keyword
- [ ] Manage worklog and estimate of issues
- [ ] Manage component and version of issues
- [ ] Track history of transitions
- [ ] More friendly help
- [ ] Improve test coverage

## Development

Expand Down
4 changes: 3 additions & 1 deletion lib/terjira.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ module Terjira
# Main CLI
class CLI < Thor
desc 'login', 'login your Jira'
option "ssl-config", type: :boolean
option "proxy-config", type: :boolean
def login
pastel = Pastel.new
Client::Base.expire_auth_options
Client::Base.build_auth_options
Client::Base.build_auth_options(options)

# for touch base resource
Client::Field.all
Expand Down
30 changes: 25 additions & 5 deletions lib/terjira/client/auth_option_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@ module Client
module AuthOptionBuilder
AUTH_CACHE_KEY = 'auth'.freeze

def build_auth_options(cache_key = AUTH_CACHE_KEY)
def build_auth_options(options = {})
cache_key = options[:cache_key] || AUTH_CACHE_KEY
auth_file_cache.fetch cache_key do
build_auth_options_by_tty
build_auth_options_by_tty(options)
end
end

def build_auth_options_by_cached(cache_key = AUTH_CACHE_KEY)
def build_auth_options_by_cached(options = {})
cache_key = options[:cache_key] || AUTH_CACHE_KEY
auth_file_cache.get(cache_key)
end

def expire_auth_options(cache_key = AUTH_CACHE_KEY)
def expire_auth_options
Terjira::FileCache.clear_all
end

def build_auth_options_by_tty
def build_auth_options_by_tty(options = {})
puts 'Login will be required...'
prompt = TTY::Prompt.new

Expand All @@ -29,8 +31,26 @@ def build_auth_options_by_tty
key(:context_path).ask('Context path:', default: '')
key(:username).ask('Username:', required: true)
key(:password).mask('Password:', required: true)

if options['ssl-config']
key(:use_ssl).yes?('Use SSL?')
key(:ssl_verify_mode).select('Verify mode:') do |menu|
menu.choice 'Verify peer', OpenSSL::SSL::VERIFY_PEER
menu.choice 'Verify client once', OpenSSL::SSL::VERIFY_CLIENT_ONCE
menu.choice 'Verify fail if no peer cert', OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
menu.choice 'Verify none', OpenSSL::SSL::VERIFY_NONE
end
end

if options['proxy-config']
key(:proxy_address).ask("Proxy address: ", default: nil)
key(:proxy_port).ask("Proxy port: ", default: nil)
end
end

result[:auth_type] = :basic
result[:use_ssl] ||= false if result[:site] =~ /http\:\/\//

result
end

Expand Down
2 changes: 1 addition & 1 deletion lib/terjira/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'terjira/utils/file_cache'

module Terjira
VERSION = '0.2.10'.freeze
VERSION = '0.3.0'.freeze

class VersionChecker
VERSION_CHECK_DURATION = (60 * 60 * 24 * 5).freeze
Expand Down
10 changes: 5 additions & 5 deletions spec/auth_option_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class TestClass
prompt.input.rewind

capture(:stdout) do
TestClass.build_auth_options('testauthpath')
result = TestClass.build_auth_options_by_cached('testauthpath')
TestClass.build_auth_options(cache_key: 'testauthpath')
result = TestClass.build_auth_options_by_cached(cache_key: 'testauthpath')
expect(result).to eq(auth_options)
end
end
Expand All @@ -36,9 +36,9 @@ class TestClass
prompt.input << inputs
prompt.input.rewind
capture(:stdout) do
TestClass.build_auth_options('testauthpath')
TestClass.expire_auth_options('testauthpath')
result = TestClass.build_auth_options_by_cached('testauthpath')
TestClass.build_auth_options(cache_key: 'testauthpath')
TestClass.expire_auth_options
result = TestClass.build_auth_options_by_cached(cache_key: 'testauthpath')
expect(result).to eq(nil)
end
end
Expand Down

0 comments on commit e545b77

Please sign in to comment.