Skip to content
This repository has been archived by the owner on Jul 29, 2021. It is now read-only.

Commit

Permalink
feat(audit): first implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGeraud authored and brasseld committed Nov 15, 2017
1 parent c0102e8 commit caec058
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -33,7 +33,7 @@
<name>Gravitee.io APIM - Repository - API</name>

<properties>
<gravitee-common.version>1.6.0</gravitee-common.version>
<gravitee-common.version>1.7.0-SNAPSHOT</gravitee-common.version>
</properties>

<dependencies>
Expand Down
@@ -0,0 +1,39 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.repository.management.api;

import io.gravitee.common.data.domain.Page;
import io.gravitee.repository.exceptions.TechnicalException;
import io.gravitee.repository.management.api.search.AuditCriteria;
import io.gravitee.repository.management.api.search.Pageable;
import io.gravitee.repository.management.model.Audit;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public interface AuditRepository extends CrudRepository<Audit, String>{

Page<Audit> search(AuditCriteria filter, Pageable pageable);

default Audit update(Audit item) throws TechnicalException {
throw new UnsupportedOperationException("Update an audit record is forbidden");
}

default void delete(String id) throws TechnicalException {
throw new UnsupportedOperationException("Delete an audit record is forbidden");
}
}
@@ -0,0 +1,151 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.repository.management.api.search;

import io.gravitee.repository.management.model.Audit;
import io.gravitee.repository.management.model.EventType;

import java.util.*;

/**
* @author Nicolas GERAUD (nicolas.geraud at graviteesource.com)
* @author GraviteeSource Team
*/
public class AuditCriteria {

private Map<Audit.AuditReferenceType, List<String>> references;

private Map<String, String> properties;

private List<String> events;

private long from, to;

AuditCriteria(AuditCriteria.Builder builder) {
this.from = builder.from;
this.to = builder.to;
this.references = new HashMap<>(builder.references);
this.properties = new HashMap<>(builder.properties);
if(builder.events != null) {
this.events = builder.events;
}
}


public Map<Audit.AuditReferenceType, List<String>> getReferences() {
return references;
}

public void setReferences(Map<Audit.AuditReferenceType, List<String>> references) {
this.references = references;
}

public Map<String, String> getProperties() {
return properties;
}

public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

public long getFrom() {
return from;
}

public void setFrom(long from) {
this.from = from;
}

public long getTo() {
return to;
}

public void setTo(long to) {
this.to = to;
}

public List<String> getEvents() {
return events;
}

public void setEvents(List<String> events) {
this.events = events;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AuditCriteria that = (AuditCriteria) o;

if (from != that.from) return false;
if (to != that.to) return false;
if (references != null ? !references.equals(that.references) : that.references != null) return false;
return properties != null ? properties.equals(that.properties) : that.properties == null;
}

@Override
public int hashCode() {
int result = references != null ? references.hashCode() : 0;
result = 31 * result + (properties != null ? properties.hashCode() : 0);
result = 31 * result + (int) (from ^ (from >>> 32));
result = 31 * result + (int) (to ^ (to >>> 32));
return result;
}

public static class Builder {
private Map<String, String> properties = new HashMap<>();

private Map<Audit.AuditReferenceType, List<String>> references = new HashMap<>();

private long from;

private long to;

private List<String> events;

public Builder from(long from) {
this.from = from;
return this;
}

public Builder to(long to) {
this.to = to;
return this;
}

public Builder references(Audit.AuditReferenceType referenceType, List<String> referenceIds) {
this.references.put(referenceType, referenceIds);
return this;
}

public Builder property(String key, String value) {
this.properties.put(key, value);

return this;
}

public Builder events(List<String> events) {
this.events = events;
return this;
}

public AuditCriteria build() {
return new AuditCriteria(this);
}
}
}
23 changes: 22 additions & 1 deletion src/main/java/io/gravitee/repository/management/model/Api.java
Expand Up @@ -25,7 +25,9 @@
* @author GraviteeSource Team
*/
public class Api {

public enum AuditEvent implements Audit.AuditEvent {
API_CREATED, API_UPDATED, API_DELETED
}
/**
* The api ID.
*/
Expand Down Expand Up @@ -95,6 +97,25 @@ public class Api {
*/
private List<String> labels;

public Api(){}

public Api(Api cloned) {
this.id = cloned.id;
this.name = cloned.name;
this.description = cloned.description;
this.version = cloned.version;
this.definition = cloned.definition;
this.deployedAt = cloned.deployedAt;
this.createdAt = cloned.createdAt;
this.updatedAt = cloned.updatedAt;
this.visibility = cloned.visibility;
this.lifecycleState = cloned.lifecycleState;
this.picture = cloned.picture;
this.groups = cloned.groups;
this.views = cloned.views;
this.labels = cloned.labels;
}

public Date getCreatedAt() {
return createdAt;
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/io/gravitee/repository/management/model/ApiKey.java
Expand Up @@ -23,6 +23,9 @@
* @author GraviteeSource Team
*/
public class ApiKey {
public enum AuditEvent implements Audit.AuditEvent {
APIKEY_CREATED, APIKEY_RENEWED, APIKEY_REVOKED, APIKEY_EXPIRED
}

/**
* Api Key
Expand Down Expand Up @@ -69,6 +72,20 @@ public class ApiKey {
*/
private Date revokedAt;


public ApiKey() {}

public ApiKey(ApiKey cloned) {
this.key = cloned.key;
this.subscription = cloned.subscription;
this.application = cloned.application;
this.plan = cloned.plan;
this.expireAt = cloned.expireAt;
this.createdAt = cloned.createdAt;
this.updatedAt = cloned.updatedAt;
this.revoked = cloned.revoked;
this.revokedAt = cloned.revokedAt;
}
public boolean isRevoked() {
return revoked;
}
Expand Down
Expand Up @@ -26,7 +26,9 @@
* @author GraviteeSource Team
*/
public class Application {

public enum AuditEvent implements Audit.AuditEvent {
APPLICATION_CREATED, APPLICATION_UPDATED, APPLICATION_ARCHIVED
}
/**
* The application ID.
*/
Expand Down Expand Up @@ -64,6 +66,19 @@ public class Application {

private ApplicationStatus status;

public Application(){}

public Application(Application cloned) {
this.id = cloned.id;
this.name = cloned.name;
this.description = cloned.description;
this.type = cloned.type;
this.createdAt = cloned.createdAt;
this.updatedAt = cloned.updatedAt;
this.groups = cloned.groups;
this.status = cloned.status;
}

public Date getCreatedAt() {
return createdAt;
}
Expand Down

0 comments on commit caec058

Please sign in to comment.