Hello, I am a bit confused by the REST syntax - how can I PUT an arbitrary file in the bucket? Downloading works fine (Perl+LWP), see below, but for PUT I only see this line in the docs (http://docs.puppetlabs.com/guides/rest_api.html): PUT /{environment}/file_bucket_file/md5/{checksum} Should I compute the MD5 of the file and port its contents at the url ? my code: my $ua = LWP::UserAgent->new(); my $ay = HTTP::Headers->new; $ay->header(''Accept'' => ''YAML''); my $as = HTTP::Headers->new; $as->header(''Accept'' => ''s''); sub get_string { my $req = HTTP::Request->new(''GET'', "https://$server/production/file_metadata/".$_[0], $ay); my $res = $ua->request($req); die "Something went wrong: ".$res->status_line unless $res->is_success; my @ini = YAML::Load($res->content."\n"); my $md5 = $ini[0]->{checksum}; $md5 =~ s/^{md5}//; $req = HTTP::Request->new(''GET'', "https://$server/production/file_bucket_file/md5/$md5", $as); $res = $ua->request($req); die "Something went wrong: ".$res->status_line unless $res->is_success; return $res->content; } sub get_yaml { my $req = HTTP::Request->new(''GET'', "https://$server/production/file_metadata/".$_[0], $ay); my $res = $ua->request($req); die "Something went wrong: ".$res->status_line unless $res->is_success; my @ini = YAML::Load($res->content."\n"); my $md5 = $ini[0]->{checksum}; $md5 =~ s/^{md5}//; $req = HTTP::Request->new(''GET'', "https://$server/production/file_bucket_file/md5/$md5", $ay); $res = $ua->request($req); die "Something went wrong: ".$res->status_line unless $res->is_success; @ini = YAML::Load($res->content."\n"); return $ini[0]; } -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Tue, May 31, 2011 at 07:21, RCosma <razvan.cosma@gmail.com> wrote:> Hello, > I am a bit confused by the REST syntax - how can I PUT an arbitrary file in > the bucket? Downloading works fine (Perl+LWP), see below, but for PUT I only > see this line in the docs (http://docs.puppetlabs.com/guides/rest_api.html): > PUT /{environment}/file_bucket_file/md5/{checksum} > Should I compute the MD5 of the file and port its contents at the url ?Yeah, you would need to: the indirector, which this is an instance of, requires that you uniquely identify where you are writing to. So, in the case of the filebucket the "key" is that MD5 checksum; you would need to calculate it for the file and supply it. There is no support in the indirector for uploading the data with the server calculating the checksum. (As a side note, I don''t think we actually *check* you were honest about that, other than when the target checksum already exists, so please try not to lie about it. ;) Daniel -- ⎋ Puppet Labs Developer – http://puppetlabs.com ✉ Daniel Pittman <daniel@puppetlabs.com> ✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775 ♲ Made with 100 percent post-consumer electrons -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thank you, and one more q: can I specify a folder/share for the uploaded file, assuming there are several available? On Tue, May 31, 2011 at 7:41 PM, Daniel Pittman <daniel@puppetlabs.com>wrote:> On Tue, May 31, 2011 at 07:21, RCosma <razvan.cosma@gmail.com> wrote: > > Hello, > > I am a bit confused by the REST syntax - how can I PUT an arbitrary file > in > > the bucket? Downloading works fine (Perl+LWP), see below, but for PUT I > only > > see this line in the docs ( > http://docs.puppetlabs.com/guides/rest_api.html): > > PUT /{environment}/file_bucket_file/md5/{checksum} > > Should I compute the MD5 of the file and port its contents at the url ? > > Yeah, you would need to: the indirector, which this is an instance of, > requires that you uniquely identify where you are writing to. So, in > the case of the filebucket the "key" is that MD5 checksum; you would > need to calculate it for the file and supply it. > > There is no support in the indirector for uploading the data with the > server calculating the checksum. > > (As a side note, I don''t think we actually *check* you were honest > about that, other than when the target checksum already exists, so > please try not to lie about it. ;) > > Daniel > -- > ⎋ Puppet Labs Developer – http://puppetlabs.com > ✉ Daniel Pittman <daniel@puppetlabs.com> > ✆ Contact me via gtalk, email, or phone: +1 (877) 575-9775 > ♲ Made with 100 percent post-consumer electrons > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Still, this doesn''t seem to work in my test setup, i.e. apache as proxy in front of puppet. I get a "..timeout specified has expired: proxy: prefetch request body failed to 127.0.0.1:18140" in apache''s log. GETs do work, just PUTs fail. Config is Listen 8140 <Proxy balancer://puppetmaster> BalancerMember http://127.0.0.1:18140 BalancerMember http://127.0.0.1:18141 </Proxy> <VirtualHost *:8140> SSLEngine On SSLCipherSuite SSLv2:-LOW:-EXPORT:RC4+RSA SSLCertificateFile /var/lib/puppet/ssl/certs/server.pem SSLCertificateKeyFile /var/lib/puppet/ssl/private_keys/server.pem SSLCertificateChainFile /var/lib/puppet/ssl/ca/ca_crt.pem SSLCACertificateFile /var/lib/puppet/ssl/ca/ca_crt.pem SSLCARevocationFile /var/lib/puppet/ssl/ca/ca_crl.pem SSLVerifyClient require SSLVerifyDepth 1 SSLOptions +StdEnvVars RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e <Location /> SetHandler balancer-manager Order allow,deny Allow from all </Location> ProxyPass / balancer://puppetmaster/ ProxyPassReverse / balancer://puppetmaster/ ProxyPreserveHost On ErrorLog /mirror/log/balancer_error_log CustomLog /mirror/log/balancer_access_log "%h %l %u %t \"%r\" %>s %b \"%{SSL_CLIENT_S_DN}x\" \"%{User-Agent}i\"" </VirtualHost> and the perl code is { open my $up, "<", "$_[0]" or die "Something went wrong: ".$!; binmode $up; my $ck = Digest::MD5->new; $ck->addfile($up); close $up; my $req = HTTP::Request::StreamingUpload->new( PUT => "https:// ".$server."/file_bucket_file/tftp/md5/".$ck->hexdigest, path => $_[0], headers => HTTP::Headers->new( ''Content-Type'' => ''application/binary'', ''Content-Length'' => -s $_[0], ''Accept'' => ''s'', ), ); my $res = $ua->request($req); die "Something went wrong: ".$res->status_line unless $res->is_success; return $res->content; } SSL handshake does work, but the puppet process doesn''t seem to receive any data (I''m tailing its debug log). Not sure if I am doing something wrong, or it is a problem in mod_proxy.. On Thu, Jun 2, 2011 at 4:47 PM, Razvan Cosma <razvan.cosma@gmail.com> wrote:> > On Tue, May 31, 2011 at 7:41 PM, Daniel Pittman <daniel@puppetlabs.com>wrote: > >> On Tue, May 31, 2011 at 07:21, RCosma <razvan.cosma@gmail.com> wrote: >> > Should I compute the MD5 of the file and port its contents at the url ? >> >> Yeah, you would need to: the indirector, which this is an instance of, >> requires that you uniquely identify where you are writing to. So, in >> the case of the filebucket the "key" is that MD5 checksum; you would >> need to calculate it for the file and supply it. >> >>-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.