forked from fabianrbz/kong-plugins-docs-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugins
executable file
·131 lines (104 loc) · 6.38 KB
/
plugins
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env ruby
require 'thor'
require_relative 'lib/schema_downloader'
require_relative 'lib/example_validator'
require_relative 'lib/data_copier'
require_relative 'lib/example_copier'
require_relative 'lib/schema_copier'
require_relative 'lib/referenceable_fields'
require_relative 'lib/plugin_priorities'
require_relative 'lib/convert_json_schema'
class Plugins < Thor
class_option :verbose, :type => :boolean
def self.exit_on_failure?
true
end
desc 'download_schemas', 'Downloads the plugins schemas in json format'
option :version, aliases: '-v', type: :string, required: true, desc: 'Kong Version'
option :plugins, aliases: '-p', type: :array, required: true, desc: 'List containing the name of the plugins'
option :host, aliases: '-d', type: :string, default: 'localhost', desc: 'Hostname of the server running the API.'
option :port, aliases: '-h', type: :numeric, default: 8001, desc: 'Port number'
option :destination, aliases: '-dest', type: :string, default: './schemas', desc: 'Destination folder where the schemas will be written'
def download_schemas
puts 'Downloading schemas...'
options[:plugins].each do |plugin|
SchemaDownloader.run!(plugin:, options:)
end
puts 'Done!'
end
desc 'validate_examples', 'Validates an example against the schema'
option :version, aliases: '-v', type: :string, required: true, default: '_index', desc: 'Kong Version'
option :plugins, aliases: '-p', type: :array, required: true, desc: 'List containing the name of the plugins'
option :host, aliases: '-d', type: :string, default: 'localhost', desc: 'Hostname of the server running the API.'
option :port, aliases: '-h', type: :numeric, default: 8001, desc: 'Port number'
option :source, aliases: '-s', type: :string, default: './examples', desc: 'Source folder containing the examples'
def validate_examples
puts 'Validating examples...'
options[:plugins].each do |plugin|
ExampleValidator.run!(plugin:, options:)
end
puts 'Done!'
end
desc 'copy_examples', 'Copy latest examples'
option :version, aliases: '-v', type: :string, required: true, default: '_index', desc: 'Kong Version'
option :plugins, aliases: '-p', type: :array, required: true, desc: 'List containing the name of the plugins'
option :source, aliases: '-s', type: :string, default: './examples', desc: 'Source folder containing the examples'
def copy_examples
puts 'Copying examples...'
options[:plugins].each do |plugin|
ExampleCopier.run!(plugin:, options:)
end
puts 'Done!'
end
desc 'copy_schemas', 'Copy latest schemas'
option :version, aliases: '-v', type: :string, required: true, default: 'index', desc: 'Kong Version'
option :plugins, aliases: '-p', type: :array, required: true, desc: 'List containing the name of the plugins'
option :source, aliases: '-s', type: :string, default: './schemas', desc: 'Source folder containing the schemas'
def copy_schemas
puts 'Copying schemas...'
options[:plugins].each do |plugin|
SchemaCopier.run!(plugin:, options:)
end
puts 'Done!'
end
desc 'copy_data_files', 'Copy data files'
option :version, aliases: '-v', type: :string, required: true, desc: 'Kong Version'
option :source, aliases: '-s', type: :string, default: './data', desc: 'Source folder containing the data files'
def copy_data_files
puts 'Copying files...'
DataCopier.run!(options:)
puts 'Done!'
end
desc 'generate_referenceable_fields_list', 'Generates a json object listing all the referenceable fields for each plugin'
option :version, aliases: '-v', type: :string, required: true, desc: 'Kong Version'
option :plugins, aliases: '-p', type: :array, required: true, desc: 'List containing the name of the plugins'
option :source, aliases: '-s', type: :string, default: './schemas', desc: 'Source folder containing the schemas'
option :destination, aliases: '-dest', type: :string, default: './data', desc: 'Destination folder where the json object containing the referenceable fields will be written'
def generate_referenceable_fields_list
puts 'Finding referenceable fields...'
ReferenceableFields.run!(plugins: options[:plugins], options: options)
puts 'Done!'
end
desc 'generate_plugin_priorities', 'Generates a json object listing all the plugins and their corresponding priorities'
option :version, aliases: '-v', type: :string, required: true, desc: 'Kong Version'
option :host, aliases: '-d', type: :string, default: 'localhost', desc: 'Hostname of the server running the API.'
option :port, aliases: '-h', type: :numeric, default: 8001, desc: 'Port number'
option :type, aliases: '-t', enum: %w(oss ee), required: true, desc: 'Specify whether the API running is the OSS or Enterprise version'
option :destination, aliases: '-dest', type: :string, default: './data', desc: 'Destination folder where the json object containing the plugins and their priorities will be written'
def generate_plugin_priorities
puts 'Listing plugins and their priorities...'
PluginPriorities.run!(options: options)
puts 'Done!'
end
desc 'convert_json_schema', 'Converts Kong plugin schema to JSON schema'
option :version, aliases: '-v', type: :string, required: true, desc: 'Kong Version'
option :plugins, aliases: '-p', type: :array, required: true, desc: 'List containing the name of the plugins'
option :source, aliases: '-s', type: :string, default: './schemas', desc: 'Source folder containing the schemas'
option :destination, aliases: '--dest', type: :string, default: './json_schemas', desc: 'Destination folder where the schemas will be written'
def convert_json_schema
puts 'Converting plugins to JSON schema...'
ConvertJsonSchema.run!(plugins: options[:plugins], options: options)
puts 'Done!'
end
end
Plugins.start(ARGV)