Skip to content
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

allow tracking of artifact hits for rest paths (defaults to false) #637

Open
wants to merge 3 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ class RestApi {
PathNode parent
List<String> fullPathList = []
Set<String> pathParameters = new LinkedHashSet<String>()
Boolean trackArtifactHit

int childPaths = 0
int childMethods = 0
Expand All @@ -589,6 +590,7 @@ class RestApi {
fullPathList.add(isId ? "{${name}}".toString() : name)
if (isId) pathParameters.add(name)
requireAuthentication = node.attribute("require-authentication") ?: parent?.requireAuthentication ?: "true"
trackArtifactHit = node.attribute("track-artifact-hit") ?: parent?.trackArtifactHit ?: false

for (MNode childNode in node.children) {
if (childNode.name == "method") {
Expand Down Expand Up @@ -645,8 +647,6 @@ class RestApi {
// push onto artifact stack, check authz
String curPath = getFullPathName([])
ArtifactExecutionInfoImpl aei = new ArtifactExecutionInfoImpl(curPath, ArtifactExecutionInfo.AT_REST_PATH, getActionFromMethod(ec), null)
// for now don't track/count artifact hits for REST path
aei.setTrackArtifactHit(false)
// NOTE: consider setting parameters on aei, but don't like setting entire context, currently used for entity/service calls
ec.artifactExecutionFacade.pushInternal(aei, !moreInPath ?
(requireAuthentication == null || requireAuthentication.length() == 0 || "true".equals(requireAuthentication)) : false, true)
Expand All @@ -660,6 +660,9 @@ class RestApi {
loggedInAnonymous = ec.userFacade.loginAnonymousIfNoUser()
}

aei.setTrackArtifactHit(trackArtifactHit)
aei.setAuthzReqdAndIsAccess(!loggedInAnonymous, true)

try {
if (moreInPath) {
String nextPath = pathList[nextPathIndex]
Expand Down
1 change: 1 addition & 0 deletions framework/src/main/resources/MoquiDefaultConf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<artifact-stats type="AT_XML_SCREEN_TRANS" persist-bin="true" persist-hit="true"/>
<artifact-stats type="AT_SERVICE" persist-bin="true" persist-hit="false"/>
<artifact-stats type="AT_ENTITY" persist-bin="false"/>
<artifact-stats type="AT_REST_PATH" persist-bin="false" persist-hit="false"/>
</server-stats>

<webapp-list>
Expand Down
1 change: 1 addition & 0 deletions framework/xsd/moqui-conf-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ along with this software (see the LICENSE.md file). If not, see
<xs:enumeration value="AT_XML_SCREEN_TRANS"/>
<xs:enumeration value="AT_SERVICE"/>
<xs:enumeration value="AT_ENTITY"/>
<xs:enumeration value="AT_REST_PATH"/>
</xs:restriction></xs:simpleType></xs:attribute>
<!-- Removed, note that entity-auto and entity-implicit service calls never have hits persisted and that is
mainly what this was used for: <xs:attribute name="sub-type" type="xs:string"/> -->
Expand Down
12 changes: 12 additions & 0 deletions framework/xsd/rest-api-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ along with this software (see the LICENSE.md file). If not, see
<xs:attribute name="description" type="xs:string"/>
<xs:attribute name="version" type="xs:string"/>
<xs:attribute name="require-authentication" type="authc-options" default="true"/>
<xs:attribute name="track-artifact-hit" type="xs:string" default="false">
<xs:annotation><xs:documentation>If set to true, ArtifactHit and ArtifactHitBin data will be kept for
this rest path unless overridden by child node(s)</xs:documentation></xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="id">
Expand All @@ -40,6 +44,10 @@ along with this software (see the LICENSE.md file). If not, see
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="require-authentication" type="authc-options" default="true"/>
<xs:attribute name="track-artifact-hit" type="xs:string" default="false">
<xs:annotation><xs:documentation>If set to true, ArtifactHit and ArtifactHitBin data will be kept for
this rest path unless overridden by child node(s)</xs:documentation></xs:annotation>
</xs:attribute>
<xs:attribute name="allow-extra-path" type="boolean" default="false">
<xs:annotation><xs:documentation>If set to true arbitrary path elements following this screen's path are allowed.
Default is false and an exception will be thrown if there is an extra path element that does not match a
Expand Down Expand Up @@ -67,6 +75,10 @@ along with this software (see the LICENSE.md file). If not, see
</xs:simpleType>
</xs:attribute>
<xs:attribute name="require-authentication" type="authc-options" default="true"/>
<xs:attribute name="track-artifact-hit" type="xs:string" default="false">
<xs:annotation><xs:documentation>If set to true, ArtifactHit and ArtifactHitBin data will be kept for
this rest path unless overridden by child node(s)</xs:documentation></xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="service">
Expand Down
Loading