Class: Swagger::IO::Security
- Inherits:
-
Object
- Object
- Swagger::IO::Security
- Defined in:
- lib/ruby-swagger/io/security.rb
Constant Summary collapse
- SECURITY_FILE_NAME =
'securityDefinitions.yml'
Class Method Summary collapse
- .read_security_definitions ⇒ Object
- .write_scopes(definition_name, definition) ⇒ Object
- .write_security_definitions(security_definitions) ⇒ Object
Class Method Details
.read_security_definitions ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby-swagger/io/security.rb', line 17 def self.read_security_definitions return nil unless Swagger::IO::FileSystem.file_exists?(SECURITY_FILE_NAME) definitions = Swagger::IO::FileSystem.read_file(SECURITY_FILE_NAME) Swagger::IO::FileSystem.all_files('/scopes/*.yml').each do |file| definitions[File.basename(file, '.yml')]['scopes'] = YAML.load_file(file) end definitions end |
.write_scopes(definition_name, definition) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby-swagger/io/security.rb', line 28 def self.write_scopes(definition_name, definition) return unless definition && definition['scopes'] scopes = definition.delete('scopes') || {} scope_file = "scopes/#{definition_name}.yml" return Swagger::IO::FileSystem.write_file(scopes.to_yaml, scope_file) unless Swagger::IO::FileSystem.file_exists?(scope_file) # Merging old scopes into new scope old_scopes = Swagger::IO::FileSystem.read_file(scope_file) Swagger::IO::FileSystem.write_file(scopes.merge(old_scopes).to_yaml, scope_file, true) end |
.write_security_definitions(security_definitions) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby-swagger/io/security.rb', line 7 def self.write_security_definitions(security_definitions) return if security_definitions.nil? || security_definitions.empty? security_definitions.each do |definition_name, definition| Swagger::IO::Security.write_scopes(definition_name, definition) end Swagger::IO::FileSystem.write_file(security_definitions.to_yaml, SECURITY_FILE_NAME) end |