knife-github 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -4
- data/lib/chef/knife/github_repo_fork.rb +154 -0
- data/lib/chef/knife/github_search.rb +2 -0
- data/lib/knife-github/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -10,11 +10,11 @@ Configurations
|
|
10
10
|
When working on customer admin machines, it's recommended to used an central configuration file.
|
11
11
|
This file should be created in: /etc/githubrc.rb and can contain any attribute in the following structure:
|
12
12
|
|
13
|
-
github_url
|
13
|
+
github_url "https://github.schubergphilis.com"
|
14
14
|
github_link "ssh"
|
15
15
|
github_organizations [ "TLA-Cookbooks", "SBP-Cookbooks" ]
|
16
16
|
|
17
|
-
Please note: these options are recommended for the central config file
|
17
|
+
Please note: these options are recommended for the central config file.
|
18
18
|
|
19
19
|
### Personal Configuration.
|
20
20
|
You can also configure attributes within your ~/.chef/knife.rb in the following structure:
|
@@ -26,12 +26,13 @@ You can also configure attributes within your ~/.chef/knife.rb in the following
|
|
26
26
|
Please note: these settings will overwrite the central settings.
|
27
27
|
In a perfect world, your personal configuration file only contains your token information.
|
28
28
|
|
29
|
+
Attributes
|
30
|
+
==========
|
31
|
+
|
29
32
|
###### github_url
|
30
33
|
This will be the URL to your (personal) github enterprise appliance.
|
31
34
|
Here you can also use the github.com address if you don't have an internal appliance.
|
32
35
|
|
33
|
-
Attributes
|
34
|
-
==========
|
35
36
|
###### github_organizations
|
36
37
|
Here you specify the organizations that you want to taget when searching for cookbooks.
|
37
38
|
The first entry will have priority over the other entries.
|
@@ -47,6 +48,11 @@ The current and default version of the api is <tt>v3</tt> but this will allow yo
|
|
47
48
|
The plugin is using the underlying knife http implementation, hence it will have the same options to handle ssl.
|
48
49
|
Currently the options are: <tt>verify_peer</tt> <tt>verify_none</tt>
|
49
50
|
|
51
|
+
###### github_token \<optional\>
|
52
|
+
Token information is required when creating and deleting github repositories.
|
53
|
+
With the command <tt>knife github token create</tt> you are able to create token information.
|
54
|
+
|
55
|
+
|
50
56
|
Other
|
51
57
|
=====
|
52
58
|
|
@@ -0,0 +1,154 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Sander Botman (<sbotman@schubergphilis.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Sander Botman.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
|
21
|
+
module KnifeGithubRepoFork
|
22
|
+
class GithubRepoFork < Chef::Knife
|
23
|
+
# Implements the knife github repo fork function
|
24
|
+
#
|
25
|
+
# == Overview
|
26
|
+
# The command will fork the repo into user-space
|
27
|
+
#
|
28
|
+
# === Examples
|
29
|
+
# Fork a new cookbook:
|
30
|
+
# knife github repo fork <name>
|
31
|
+
#
|
32
|
+
# === Options
|
33
|
+
# -t --github_token Authentication token for the github.
|
34
|
+
#
|
35
|
+
|
36
|
+
deps do
|
37
|
+
require 'chef/knife/github_base'
|
38
|
+
include Chef::Knife::GithubBase
|
39
|
+
end
|
40
|
+
|
41
|
+
banner "knife github repo fork <name> [owner] [target] (options)"
|
42
|
+
category "github"
|
43
|
+
|
44
|
+
option :github_token,
|
45
|
+
:short => "-t",
|
46
|
+
:long => "--github_token",
|
47
|
+
:description => "Your github token for OAuth authentication"
|
48
|
+
|
49
|
+
def run
|
50
|
+
params = {}
|
51
|
+
# validate base options from base module.
|
52
|
+
validate_base_options
|
53
|
+
|
54
|
+
# Display information if debug mode is on.
|
55
|
+
display_debug_info
|
56
|
+
|
57
|
+
# Get the name_args from the command line
|
58
|
+
name = name_args[0]
|
59
|
+
name_args[1].nil? ? owner = locate_config_value('github_organizations').first : owner = name_args[1]
|
60
|
+
target = name_args[2] unless name_args[2].nil?
|
61
|
+
|
62
|
+
if owner.nil? || name.nil? || owner.empty? || name.empty?
|
63
|
+
Chef::Log.error("Please specify a repository name like: name ")
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
|
67
|
+
# Set params for the rest request
|
68
|
+
params['url'] = @github_url + "/api/" + @github_api_version + "/repos/#{owner}/#{name}/forks"
|
69
|
+
params['body'] = get_body_json(target) unless target.nil?
|
70
|
+
params['token'] = get_github_token()
|
71
|
+
params['response_code'] = 202
|
72
|
+
|
73
|
+
# Execute the rest request
|
74
|
+
username = ENV['USER']
|
75
|
+
|
76
|
+
rest_request(params)
|
77
|
+
if target
|
78
|
+
puts "Fork of #{name} is created in #{target}"
|
79
|
+
else
|
80
|
+
puts "Fork of #{name} is created in #{username}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Create the json body with repo config for POST information
|
85
|
+
# @param target [String] oragnization target name
|
86
|
+
def get_body_json(target)
|
87
|
+
body = {
|
88
|
+
"organization" => target,
|
89
|
+
}.to_json
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get the OAuth authentication token from config or command line
|
93
|
+
# @param nil
|
94
|
+
def get_github_token()
|
95
|
+
token = locate_config_value('github_token')
|
96
|
+
if token.nil? || token.empty?
|
97
|
+
Chef::Log.error("Please specify a github token")
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
token
|
101
|
+
end
|
102
|
+
|
103
|
+
# Post Get the OAuth authentication token from config or command line
|
104
|
+
# @param url [String] target url (organization or user)
|
105
|
+
# body [JSON] json data with repo configuration
|
106
|
+
# token [String] token sring
|
107
|
+
def rest_request(params = {})
|
108
|
+
url = params['url'].to_s
|
109
|
+
token = params['token'].to_s
|
110
|
+
code = params['response_code'] || 200
|
111
|
+
body = params['body'] || nil
|
112
|
+
action = params['action'] || 'POST'
|
113
|
+
|
114
|
+
if @github_ssl_verify_mode == "verify_none"
|
115
|
+
config[:ssl_verify_mode] = :verify_none
|
116
|
+
elsif @github_ssl_verify_mode == "verify_peer"
|
117
|
+
config[:ssl_verify_mode] = :verify_peer
|
118
|
+
end
|
119
|
+
|
120
|
+
Chef::Log.debug("URL: " + url)
|
121
|
+
|
122
|
+
uri = URI.parse(url)
|
123
|
+
http = Net::HTTP.new(uri.host,uri.port)
|
124
|
+
if uri.scheme == "https"
|
125
|
+
http.use_ssl = true
|
126
|
+
if @github_ssl_verify_mode == "verify_none"
|
127
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
128
|
+
else
|
129
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
req = Net::HTTP::Post.new(uri.path, initheader = {"Authorization" => "token #{token}"})
|
134
|
+
req.body = body unless body.nil?
|
135
|
+
response = http.request(req)
|
136
|
+
|
137
|
+
unless response.code.to_s == code.to_s then
|
138
|
+
puts "Error #{response.code}: #{response.message}"
|
139
|
+
puts JSON.pretty_generate(JSON.parse(response.body))
|
140
|
+
puts "URL: #{url}"
|
141
|
+
exit 1
|
142
|
+
end
|
143
|
+
|
144
|
+
begin
|
145
|
+
json = JSON.parse(response.body)
|
146
|
+
rescue
|
147
|
+
ui.warn "The result on the RESTRequest is not in json format"
|
148
|
+
ui.warn "Output: " + response.body
|
149
|
+
exit 1
|
150
|
+
end
|
151
|
+
json
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
data/lib/knife-github/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mixlib-versioning
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/chef/knife/github_pin.rb
|
114
114
|
- lib/chef/knife/github_repo_create.rb
|
115
115
|
- lib/chef/knife/github_repo_destroy.rb
|
116
|
+
- lib/chef/knife/github_repo_fork.rb
|
116
117
|
- lib/chef/knife/github_search.rb
|
117
118
|
- lib/chef/knife/github_token_create.rb
|
118
119
|
- lib/knife-github/config.rb
|