-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Large refactoring #4 With the old funtionality it was OK to always need a node, because a user had to choose one after choosing an environment. With #4 we are introducing a different funtionality that should work indepently of a node. This is in preparation of #4 and tries to disentangle environment, nodes and everything else. To accomplish this, "proper" abstractions for all relevant parts of the hiera data model are introduced (hierarchies, data_files and values). Due to the git backend, (data_)file and value handling still need to be able to work with a node's facts, but this has been made optional. * First draft of key search #4 * Disable misguided cop #4 * Collapse search results by default #4 Lists of files may get very long. This way, a user can open just the hierarchy she wants. * Cleanup and some tests #4
- Loading branch information
Showing
39 changed files
with
557 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class FilesController < ApplicationController | ||
before_action :load_environments | ||
before_action :load_key | ||
|
||
add_breadcrumb "Home", :root_path | ||
add_breadcrumb "Environments", :environments_path | ||
|
||
def index | ||
@files_and_values_by_hierarchy = DataFile.search(@environment, @key) | ||
|
||
add_breadcrumb @environment, environment_nodes_path(@environment) | ||
add_breadcrumb @key, environment_key_files_path(@environment, @key) | ||
end | ||
|
||
private | ||
|
||
def load_key | ||
@key = Key.new(environment: @environment, name: params[:key_id].squish) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class ValuesController < ApplicationController | ||
before_action :instantiate_models | ||
|
||
def update | ||
authorize! :update, Key | ||
|
||
@value.update(params[:value], node: @node) | ||
|
||
redirect_to environment_node_key_path(@environment, @node, @key), | ||
notice: "Value was saved successfully" | ||
end | ||
|
||
def destroy | ||
authorize! :destroy, Key | ||
|
||
@value.destroy(node: @node) | ||
|
||
redirect_to environment_node_key_path(@environment, @node, @key), | ||
status: :see_other, | ||
notice: "Value was removed successfully" | ||
end | ||
|
||
private | ||
|
||
def instantiate_models | ||
@environment = Environment.find(params[:environment_id]) | ||
@node = Node.new(hostname: params[:node_id], environment: @environment) | ||
@hierarchy = Hierarchy.find(@environment, params[:hierarchy_id]) | ||
@data_file = DataFile.new(hierarchy: @hierarchy, path: params[:data_file_id]) | ||
@key = Key.new(environment: @environment, name: params[:key_id]) | ||
@value = @data_file.value_for(key: @key) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/javascript/controllers/text_input_navigation_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { Turbo } from "@hotwired/turbo-rails" | ||
|
||
// Connects to data-controller="text-input-navigation" | ||
export default class extends Controller { | ||
static targets = ["input"] | ||
static values = {placeholder: String, url: String} | ||
|
||
navigate() { | ||
const trimmedValue = this.inputTarget.value.trim() | ||
const url = this.urlValue.replace(this.placeholderValue, trimmedValue); | ||
Turbo.visit(url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
class DataFile < HieraModel | ||
attribute :hierarchy | ||
attribute :node | ||
attribute :path, :string | ||
attribute :exist, :boolean, default: false | ||
attribute :writable, :boolean, default: false | ||
attribute :replaced_from_git, :boolean, default: false | ||
|
||
delegate :environment, to: :hierarchy | ||
|
||
def self.search(environment, key) | ||
hierarchies = {} | ||
result = {} | ||
HieraData.new(environment.name).files_including(key.name).each do |file| | ||
hierarchies[file[:hierarchy_name]] ||= Hierarchy.new( | ||
environment: environment, | ||
name: file[:hierarchy_name], | ||
backend: file[:hierarchy_backend] | ||
) | ||
data_file = new( | ||
hierarchy: hierarchies[file[:hierarchy_name]], | ||
path: file[:path] | ||
) | ||
value = Value.new(data_file: data_file, key: key, value: file[:value]) | ||
result[hierarchies[file[:hierarchy_name]]] ||= {} | ||
result[hierarchies[file[:hierarchy_name]]][data_file] = value | ||
end | ||
result | ||
end | ||
|
||
def initialize(attributes = {}) | ||
super(attributes) | ||
file_attributes = hiera_data.file_attributes(hierarchy.name, path, facts: node&.facts) | ||
self.exist = file_attributes[:exist] | ||
self.writable = file_attributes[:writable] | ||
self.replaced_from_git = file_attributes[:replaced_from_git] | ||
end | ||
|
||
def keys | ||
@keys ||= hiera_data.keys_in_file(hierarchy.name, path).map do |key_name| | ||
Key.new(environment: environment, name: key_name) | ||
end | ||
end | ||
|
||
def has_key?(key) | ||
keys.include?(key) | ||
end | ||
|
||
def value_for(key:) | ||
raw_value = (hiera_data.value_in_file(hierarchy.name, path, key.name, facts: node&.facts) if has_key?(key)) # rubocop:disable Style/PreferredHashMethods | ||
Value.new(data_file: self, key: key, value: raw_value) | ||
end | ||
|
||
def writable? | ||
!Rails.configuration.hdm.read_only && attributes["writable"] | ||
end | ||
|
||
def exist? | ||
exist | ||
end | ||
|
||
def replaced_from_git? | ||
replaced_from_git | ||
end | ||
|
||
def to_param | ||
path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class HieraModel | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
private | ||
|
||
def hiera_data | ||
@hiera_data ||= HieraData.new(environment.name) if respond_to?(:environment) | ||
end | ||
end |
Oops, something went wrong.