From: Matt S Trout Date: Tue, 4 Mar 2014 02:47:30 +0000 (+0000) Subject: commit sketch files X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=96add15b820b897e0451398da92cfed3818f578e;p=scpubgit%2FDKit.git commit sketch files --- diff --git a/notes/sketches/1.fs b/notes/sketches/1.fs new file mode 100644 index 0000000..eed5a1b --- /dev/null +++ b/notes/sketches/1.fs @@ -0,0 +1,11 @@ +path_status PS P +is_directory PS +is_file PS +perms PS P + +fact_type path_status DX::Lib::FS::Fact::PathStatus path + +observe path_status DX::Lib::FS::Observation::PathStatus + +constraint is_directory { $_[0]->has_info and $_[0]->info->is_directory } +constraint is_file { $_[0]->has_info and $_[0]->info->is_file } diff --git a/notes/sketches/2.fs.arrayref.form b/notes/sketches/2.fs.arrayref.form new file mode 100644 index 0000000..d9e7289 --- /dev/null +++ b/notes/sketches/2.fs.arrayref.form @@ -0,0 +1,13 @@ + [ path_status => [ qw(PathStatus Path) ], + [ member_lookup => qw(PathStatus path_status path Path) ] ], + [ path_status => [ qw(PathStatus Path) ], + [ observe => qw(PathStatus path_status DX::Lib::FS::Observation::PathStatus path Path) ], + [ member_lookup => qw(PathStatus path_status path Path) ] ], + [ is_directory => [ 'PS' ], + [ constrain => [ 'PS' ], sub { $_[0]->has_info and $_[0]->info->is_directory } ] ], + [ is_file => [ 'PS' ], + [ constrain => [ 'PS' ], sub { $_[0]->has_info and $_[0]->info->is_file } ] ], + [ directory_at => [ qw(D P) ], + [ call => path_status => qw(D P) ], + [ call => is_directory => 'D' ] ], + diff --git a/notes/sketches/3.fs.pseudocode b/notes/sketches/3.fs.pseudocode new file mode 100644 index 0000000..f8ef79d --- /dev/null +++ b/notes/sketches/3.fs.pseudocode @@ -0,0 +1,10 @@ +is_directory D + expr { $_{D}->is_directory } + +make is_directory D + where not exists_path D + via Action::MakePath->new(path => $d->path) + +make perms PS Mode + where creating PS Action + via derive Action { mode => $Mode } diff --git a/notes/sketches/4.km.pseudo b/notes/sketches/4.km.pseudo new file mode 100644 index 0000000..c52b24c --- /dev/null +++ b/notes/sketches/4.km.pseudo @@ -0,0 +1,77 @@ +rule my_config_dir D { + on 'localhost' { + directory_at D '.keymangler' + } +} + +rule my_config_file F Name { + exists D { my_config_dir D; file_in D Name F } +} + +rule known_account A { + exists F { my_config_file F 'accounts'; contains-line F A } +} + +rule known_key K { + exists F { my_config_file F 'keys'; contains-line F K } +} + +rule known_dead D { + exists F { my_config_file F 'keys.dead'; contains-line F D } +} + +rule dot_ssh D { + directory_at D '.ssh' { + mode '0755' + } +} + +rule keys_file_in {D F} { + file_in D 'authorized_keys' { + mode '0644' + } +} + +rule keys_file F { exists D { dot_ssh D; keys_file_in D F } } + +rule key_installed K { + exists F { + keys_file F + contains_line F K + } +} + +rule key_not_installed K { + not exists F { keys_file F } +} + +rule key_not_installed K { + given F { keys_file F } { + not_contains_line F K + } +} + +action sync_account A { + on A { + forall K { known_key K } { ensure key_installed K } + forall D { known_dead D } { ensure key_not_installed D } + } +} + +action sync { + forall A { known_account A } { + sync_account A + } +} + +action installed_on A { + on A { + forall K { key_installed K } { print K } + } +} + +action unknown_installed_on A { + on A { + forall K { key_installed K; not known_key K } { print K } + } +} diff --git a/notes/sketches/5.km.commands.psuedo b/notes/sketches/5.km.commands.psuedo new file mode 100644 index 0000000..4615472 --- /dev/null +++ b/notes/sketches/5.km.commands.psuedo @@ -0,0 +1,53 @@ +command learn { + command key K { + ensure { known_key K } + } + command dead D { + ensure { known_dead D } + } + command account A { + ensure { known_account A } + } +} + +command forget { + command key K { + ensure { not_known_key K } + } + command dead D { + ensure { not_known_dead D } + } + command account A { + ensure { not_known_account A } + } +} + +command list { + command keys {} { + query* { known_key K } { puts $K } + } + command dead {} { + query* { known_dead D } { puts $D } + } + command accounts {} { + query* { known_account A } { puts $A } + } +} + +command sync {} { ensure all_synchronized } + +command sync A { ensure { account_synchronized A } } + +command status {} { + query* { + known_account A + findall Known K { known_installed_on A K } + findall Unknown U { unknown_installed_on A U } + findall Dead D { dead_installed_on A D } + } { + puts "Host: $A" + foreach k $Known { puts "Known: $k" } + foreach u $Unknown { puts "Unknown: $u" } + foreach d $Dead { puts "Dead: $d" } + } +}