1# OpenXPKI::Server::Workflow::Activity::CertIssuance::TriggerCertificatePublish
2#
3# Copyright (c) 2012 by The OpenXPKI Project
4
5package OpenXPKI::Server::Workflow::Activity::Tools::TriggerCertificatePublish;
6
7use strict;
8use base qw( OpenXPKI::Server::Workflow::Activity );
9
10use OpenXPKI::Server::Context qw( CTX );
11use OpenXPKI::Exception;
12use OpenXPKI::Debug;
13use OpenXPKI::Serialization::Simple;
14
15
16use Data::Dumper;
17
18sub execute {
19    my $self = shift;
20    my $workflow = shift;
21    my $context = $workflow->context();
22
23    # Add any additional action parameters as context params
24    my $params = $self->param();
25
26    my $workflow_type = 'certificate_publishing';
27
28    if ($params->{'workflow_type'}) {
29        $workflow_type = $params->{'workflow_type'};
30        delete $params->{'workflow_type'};
31    }
32
33    # cert identifier is mandatory
34    if (!$params->{cert_identifier}) {
35        $params->{cert_identifier} = $context->param('cert_identifier');
36    }
37
38    # Check profile based publishing if no prefix is set in the action definition
39    if (!$params->{prefix}) {
40        # Profile based publication, check for publication options
41        my $cert_profile = $params->{'cert_profile'} || $context->param('cert_profile');
42        $cert_profile = CTX('api2')->get_profile_for_cert( identifier => $params->{cert_identifier} ) unless($cert_profile);
43
44        if (!$cert_profile) {
45            $cert_profile = 'default';
46            CTX('log')->application()->debug('no profile found for publishing rules - using default');
47        }
48
49        my $config_key = $params->{unpublish} ? 'unpublish' : 'publish';
50        if (!CTX('config')->get_scalar_as_list(['profile', $cert_profile, $config_key ] ) &&
51            !CTX('config')->get_scalar_as_list(['profile', 'default', $config_key ] )) {
52
53            ##! 32: 'Publishing not enabled for profile ' . $cert_profile
54            CTX('log')->application()->debug('Publishing not enabled for profile ' . $cert_profile);
55
56            return 1;
57        }
58    }
59
60    # Create publishing workflow
61    my $wf_info = CTX('api2')->create_workflow_instance(
62        workflow      => $workflow_type,
63        params        => $params,
64        norun         => 'detach',
65        _run_as_system => 1,
66        ($workflow->attrib('tenant') ? (tenant => $workflow->attrib('tenant')) : ()),
67    );
68
69    CTX('log')->application()->info('Publishing workflow created with id ' . $wf_info->{workflow}->{id});
70
71
72    ##! 16: 'Publishing Workflow created with id ' . $wf_info->{workflow}->{id}
73
74    $context->param('workflow_publish_id', $wf_info->{workflow}->{id} );
75
76    return 1;
77
78}
79
80
811;
82__END__
83
84=head1 Name
85
86OpenXPKI::Server::Workflow::Activity::Tools::TriggerCertificatePublish
87
88=head1 Description
89
90Trigger publication to by starting (unwatched) workflows. The name of the
91publication workflow can be given in the activity definition, default is
92certificate_publishing.
93
94If no more parameters are given, the publication will happen based on the
95publication options of the profile. A workflow is only created if the "publish"
96attribute is set in the certificates profile definition or a global publish
97rule (in profile.default) exists.
98
99If the parameter I<prefix> is set in the definiton, publication to all
100targets at this prefix is startet, regardless if the profile has a publication
101option set.
102
103=head1 Configuration
104
105=head2 Activity parameters
106
107=over
108
109=item cert_identifier
110
111Certificate to publish, mandatory - if not set tries to read it directly
112from the context.
113
114=item cert_profile
115
116If not set the class reads it from the context. If not set in context the
117class tries to determine the profile from the database.
118
119=item workflow_type
120
121Name of the workflow that should be created, default is certificate_publishing
122
123=item prefix
124
125Prefix to list of publishing connectors, default is profile based publishing.
126
127=item unpublish
128
129If set and profile mode is active, the attribute I<unpublish> will be checked
130instead of I<publish>.
131
132=back
133
134All other activity parameters are passed as parameters to the new workflow.
135Make sure that those parameters are listed in the initial action of the
136called workflow!
137
138=head2 Context parameters
139
140Expects the following context parameter:
141
142=over 12
143
144=item cert_identifier (can be overridden in the an activity definition)
145
146=item cert_profile (obsolete when using prefix)
147
148=back
149
150=head1 Functions
151
152=head2 execute
153
154Executes the action.
155