Skip to content

add ability to create secret #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions providers/secret.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def load_current_resource
@current_resource = Chef::Resource::LibvirtSecret.new(new_resource.name)
@libvirt = ::Libvirt.open(new_resource.uri)
@current_resource
end

action :define do
require 'base64'
uuid = new_resource.uuid || ::UUIDTools::UUID.random_create
begin
new_secret_xml = <<-EOF
<secret ephemeral='#{new_resource.ephemeral}' private='#{new_resource.private}'>
<uuid>#{new_resource.uuid}</uuid>
<usage type='#{new_resource.type}'>
<name>#{new_resource.name}</name>
</usage>
</secret>
EOF
conn = Libvirt::open(new_resource.uri)
secret = conn.define_secret_xml(new_secret_xml)
secret.value = Base64.decode64(new_resource.value)
rescue Libvirt::RetrieveError
raise "ERROR"
end
end
14 changes: 14 additions & 0 deletions resources/secret.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
actions :define, :undefine

def initialize(*args)
super
@action = :define
end

attribute :name, :kind_of => String, :name_attribute => true
attribute :type, :kind_of => String, :required => true, :default => 'ceph'
attribute :ephemeral, :kind_of => String, :default => 'no'
attribute :private, :kind_of => String, :default => 'no'
attribute :uuid, :kind_of => String
attribute :value, :kind_of => String, :required => true
attribute :uri, :kind_of => String, :default => 'qemu:///system'