Skip to content

Commit

Permalink
refactor: split evaluations into SBOM or License for given user input (
Browse files Browse the repository at this point in the history
  • Loading branch information
spiffcs authored Dec 6, 2023
1 parent be0c829 commit 102131d
Show file tree
Hide file tree
Showing 45 changed files with 1,776 additions and 775 deletions.
22 changes: 12 additions & 10 deletions .grant.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#.grant.yaml
precedence: [deny, allow]
deny-licenses: "*"
allow-licenses:
- MPL-2.0
- BSD-2-Clause
- BSD-3-Clause
- GPL-2.0-Or-Later+
- Zlib
- MIT
- Apache-2.0
format: json
import:
- ../local-policy.json
- git@githubcom:anchore/central-policy.git@main#./org/*.policy.json
- allowed: []
denied: []
# grant -o json alpine:latest=osi.arrpoved.json enterprisesystemsengineering:latest=special.approved.json
# grant myimage:latest ./local-policy.json

# .gitignore vs .gitconfig distinction (don't mix the what and how)

# .grantpolicy.yaml
# .grantpolicy/*.yaml
10 changes: 5 additions & 5 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ tasks:
- build
deps: [tools]
cmds:
- silent: true
cmd: |
echo "dist: {{ .SNAPSHOT_DIR }}" > {{ .TMP_DIR }}/goreleaser.yaml
- cmd: "mkdir -p {{ .TMP_DIR }}"
silent: true
- cmd: |
cat .goreleaser.yaml >> {{ .TMP_DIR }}/goreleaser.yaml
- "{{ .TOOL_DIR }}/goreleaser release --clean --skip=publish --skip=sign --snapshot --config {{ .TMP_DIR }}/goreleaser.yaml"
echo "dist: {{ .SNAPSHOT_DIR }}" >> {{ .TMP_DIR }}/goreleaser.yaml
- cmd: "{{ .TOOL_DIR }}/goreleaser release --clean --skip=publish --skip=sign --snapshot --config {{ .TMP_DIR }}/goreleaser.yaml"


## TODO Release targets #################################
3 changes: 2 additions & 1 deletion cmd/grant/cli/command/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/anchore/clio"
"github.com/anchore/grant/cmd/grant/cli/option"
"github.com/anchore/grant/grant"
"github.com/anchore/grant/grant/report"
"github.com/anchore/grant/internal/input"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ func runCheck(cfg CheckConfig, sources []string) (errs error) {
}

// TODO: we need to support the ability to write the report to a file without redirecting stdout
return grant.NewReport(grant.Format(cfg.Format), policy, sources...).
return report.NewReport(report.Format(cfg.Format), policy, sources...).
Run().
Render(os.Stdout)
}
3 changes: 2 additions & 1 deletion cmd/grant/cli/internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func (m *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}

for _, newModel := range m.handler.Handle(msg) {
handlerModels, _ := m.handler.Handle(msg)
for _, newModel := range handlerModels {
if newModel == nil {
continue
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/grant/cli/option/check.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package option

import "github.com/anchore/grant/grant"
import (
"github.com/anchore/grant/grant"
)

type Check struct {
AllowLicenses []string `json:"allow-licenses" yaml:"allow-licenses" mapstructure:"allow-licenses"`
Expand Down
6 changes: 3 additions & 3 deletions cmd/grant/cli/tui/handle_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (

var _ tea.Model = (*checkViewModel)(nil)

func (m *Handler) handleCLICheckCmdStarted(e partybus.Event) []tea.Model {
func (m *Handler) handleCLICheckCmdStarted(e partybus.Event) ([]tea.Model, tea.Cmd) {
sourceNames, prog, err := event.ParseCheckCommandStarted(e)
if err != nil {
log.WithFields("error", err).Warn("unable to parse event")
return nil
return nil, nil
}

return []tea.Model{newCheckViewModel(sourceNames, prog, m.WindowSize)}
return []tea.Model{newCheckViewModel(sourceNames, prog, m.WindowSize)}, nil
}

type checkViewModel struct {
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions fixtures/archive-builds/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/packages/*

# maven when running in a volume may spit out directories like this
**/\?/
\?/
19 changes: 19 additions & 0 deletions fixtures/archive-builds/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PKGSDIR=packages

ifndef PKGSDIR
$(error PKGSDIR is not set)
endif

clean: clean-examples
rm -f $(PKGSDIR)/*

jars: $(PKGSDIR)/example-java-app-maven-0.1.0.jar

archives: $(PKGSDIR)/example-java-app-maven-0.1.0.zip

$(PKGSDIR)/example-java-app-maven-0.1.0.zip: $(PKGSDIR)/example-java-app-maven-0.1.0.jar
zip $(PKGSDIR)/example-java-app-maven-0.1.0.zip $(PKGSDIR)/example-java-app-maven-0.1.0.jar

# Maven...
$(PKGSDIR)/example-java-app-maven-0.1.0.jar:
./build-example-java-app-maven.sh $(PKGSDIR)
17 changes: 17 additions & 0 deletions fixtures/archive-builds/build-example-java-app-maven.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -uxe

PKGSDIR=$1
CTRID=$(docker create -u "$(id -u):$(id -g)" -e MAVEN_CONFIG=/tmp/.m2 -v /example-java-app -w /example-java-app maven:3.8.6-openjdk-18 mvn -Duser.home=/tmp -DskipTests package)

function cleanup() {
docker rm "${CTRID}"
}

trap cleanup EXIT
set +e

docker cp "$(pwd)/example-java-app" "${CTRID}:/"
docker start -a "${CTRID}"
mkdir -p "$PKGSDIR"
docker cp "${CTRID}:/example-java-app/target/example-java-app-maven-0.1.0.jar" "$PKGSDIR"
6 changes: 6 additions & 0 deletions fixtures/archive-builds/example-java-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# maven build creates this when in a container volume
/?/
/.gradle/
/build/
target/
dependency-reduced-pom.xml
58 changes: 58 additions & 0 deletions fixtures/archive-builds/example-java-app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
plugins {
id 'java'
id 'eclipse'
id 'application'
}

mainClassName = 'hello.HelloWorld'

dependencyLocking {
lockAllConfigurations()
}
// tag::repositories[]
repositories {
mavenCentral()
}
// end::repositories[]

// tag::dependencies[]
sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
implementation "joda-time:joda-time:2.2"
testImplementation "junit:junit:4.12"
}
// end::dependencies[]

// tag::jar[]
jar {
archivesBaseName = 'example-java-app-gradle'
version = '0.1.0'
manifest {
attributes(
'Main-Class': 'hello.HelloWorld'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
// end::jar[]

// tag::wrapper[]
// end::wrapper[]

// to invoke: gradle resolveAndLockAll --write-locks
tasks.register('resolveAndLockAll') {
notCompatibleWithConfigurationCache("Filters configurations at execution time")
doFirst {
assert gradle.startParameter.writeDependencyLocks
}
doLast {
configurations.findAll {
// Add any custom filtering on the configurations to be resolved
it.canBeResolved
}.each { it.resolve() }
}
}
7 changes: 7 additions & 0 deletions fixtures/archive-builds/example-java-app/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
joda-time:joda-time:2.2=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
junit:junit:4.12=testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest-core:1.3=testCompileClasspath,testRuntimeClasspath
empty=annotationProcessor,testAnnotationProcessor
59 changes: 59 additions & 0 deletions fixtures/archive-builds/example-java-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.anchore</groupId>
<artifactId>example-java-app-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- tag::joda[] -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
<!-- end::joda[] -->
<!-- tag::junit[] -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- end::junit[] -->
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hello;

public class Greeter {
public String sayHello() {
return "Hello world!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hello;

import org.joda.time.LocalTime;

public class HelloWorld {
public static void main(String[] args) {
LocalTime currentTime = new LocalTime();
System.out.println("The current local time is: " + currentTime);

Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
7 changes: 7 additions & 0 deletions fixtures/licenses/MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright <YEAR> <COPYRIGHT HOLDER>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit 102131d

Please sign in to comment.