# Generated by go2rpm 1.3
%bcond_without check

# https://github.com/open-policy-agent/opa
%global goipath         github.com/open-policy-agent/opa
Version:                0.31.0
# short_commit is used to display in opa version
%global short_commit    e88ad165

%gometa

%global common_description %{expand:
An open source, general-purpose policy engine.

The Open Policy Agent (OPA) is an open source, general-purpose policy engine
that enables unified, context-aware policy enforcement across the entire
stack.}

%global golicenses      LICENSE LICENSE-jwx
%global godocs          docs/content CHANGELOG.md README.md MAINTAINERS.md\\\
                        ADOPTERS.md CODE_OF_CONDUCT.md CONTRIBUTING.md\\\
                        GOVERNANCE.md SECURITY.md

Name:           open-policy-agent
Release:        10%{?dist}
Summary:        Open source, general-purpose policy engine

# Upstream license specification: MIT and Apache-2.0
# Main package:    ASL 2.0
# internal/jwx:    MIT
# internal/semver: ASL 2.0
License:        ASL 2.0 and MIT
URL:            %{gourl}
Source0:        %{gosource}
# Make telemetry opt-out
Patch0:         0001-Make-telemetry-opt-out.patch
# Skip tests requiring network
Patch1:         0001-Skip-tests-requiring-network.patch
# Warn users about WebAssembly missing
Patch2:         0001-Warn-users-about-WebAssembly-missing.patch
# Fix tests by updating expired SSL certificates used in tests fixtures
Patch3:         https://github.com/open-policy-agent/opa/pull/3919.patch#/0001-Update-certs.patch

BuildRequires:  golang(github.com/fsnotify/fsnotify)
BuildRequires:  golang(github.com/ghodss/yaml)
BuildRequires:  golang(github.com/gobwas/glob)
BuildRequires:  golang(github.com/gorilla/mux)
BuildRequires:  golang(github.com/olekukonko/tablewriter)
BuildRequires:  golang(github.com/OneOfOne/xxhash)
BuildRequires:  golang(github.com/peterh/liner)
BuildRequires:  golang(github.com/pkg/errors)
BuildRequires:  golang(github.com/prometheus/client_golang/prometheus)
BuildRequires:  golang(github.com/prometheus/client_golang/prometheus/promhttp)
BuildRequires:  golang(github.com/rcrowley/go-metrics)
BuildRequires:  golang(github.com/sirupsen/logrus)
BuildRequires:  golang(github.com/spf13/cobra)
BuildRequires:  golang(github.com/spf13/pflag)
BuildRequires:  golang(github.com/xeipuuv/gojsonreference)
BuildRequires:  golang(github.com/yashtewari/glob-intersection)
BuildRequires:  golang(go.uber.org/automaxprocs/maxprocs)
BuildRequires:  golang(golang.org/x/net/http2)
BuildRequires:  golang(golang.org/x/net/http2/h2c)
BuildRequires:  golang(golang.org/x/time/rate)
BuildRequires:  golang(gopkg.in/yaml.v2)

%if %{with check}
# Tests
BuildRequires:  golang(github.com/stretchr/testify/assert)
BuildRequires:  golang(github.com/stretchr/testify/require)
%endif

%description
%{common_description}

%gopkg

%prep
%goprep
%autopatch -p1
mv internal/jwx/LICENSE LICENSE-jwx

# Remove code related to wasm, as we have to disable wasm,
# wasmtime not being packaged in Fedora yet
rm resolver/wasm/wasm.go version/wasm.go
rm internal/rego/opa/opa.go internal/wasm/sdk/opa/capabilities/capabilities.go
rm -rf internal/wasm/sdk/internal/wasm internal/wasm/sdk/opa/opa.go

# Fix tests failing with Go >= 1.17
sed -i 's/asn1: structure error/x509: malformed certificate/' test/cases/testdata/cryptox509parsecertificates/test-cryptox509parsecertificates-0123.yaml

%build
%gobuild -o %{gobuilddir}/bin/generate-man %{goipath}/build/generate-man
export LDFLAGS="-X %{goipath}/version.Version=%{version} -X %{goipath}/version.Vcs=%{short_commit} -X %{goipath}/version.Timestamp=$(./build/get-build-timestamp.sh) "
%gobuild -o %{gobuilddir}/bin/opa %{goipath}
mkdir _man
%{gobuilddir}/bin/generate-man _man
rm %{gobuilddir}/bin/generate-man

%install
%gopkginstall
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/
install -d -p -m 0755                   %{buildroot}%{_mandir}/man1
install -D -p -m 0644 _man/*            %{buildroot}%{_mandir}/man1/

%if %{with check}
%check
%gocheck -t internal/wasm -t sdk
%endif

%files
%license LICENSE LICENSE-jwx
%doc docs/content CHANGELOG.md README.md MAINTAINERS.md ADOPTERS.md CODE_OF_CONDUCT.md
%doc CONTRIBUTING.md GOVERNANCE.md SECURITY.md
%{_mandir}/man1/opa*.1*
%{_bindir}/*

%gopkgfiles

%changelog
* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.31.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Wed Aug 10 2022 Maxwell G <gotmax@e.email> - 0.31.0-9
- Rebuild to fix FTBFS

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.31.0-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jul 19 2022 Maxwell G <gotmax@e.email> - 0.31.0-7
- Rebuild for CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in
  golang

* Thu Jun 23 2022 Maxwell G <gotmax@e.email> - 0.31.0-6
- Rebuild to mitigate CVE-2022-21698 (rhbz#2067400).

* Sat Jun 18 2022 Robert-André Mauchin <zebob.m@gmail.com> - 0.31.0-5
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327, CVE-2022-27191,
  CVE-2022-29526, CVE-2022-30629

* Sat Apr 16 2022 Fabio Alessandro Locati <me@fale.io> - 0.31.0-4
- Rebuilt for CVE-2022-27191

* Wed Feb 02 2022 Olivier Lemasle <o.lemasle@gmail.com> - 0.31.0-3
- Fix failing tests (fixes rhbz#2046783)

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.31.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Sun Aug 15 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.31.0-1
- Update to latest upstream 0.31.0 (fixes rhbz#1987088)

* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.30.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Wed Jul 14 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.30.2-1
- Update to latest upstream 0.30.2 (fixes rhbz#1982007)

* Fri Jul 02 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.30.1-1
- Update to latest upstream 0.30.1 (fixes rhbz#1978733)

* Thu Jul 01 11:17:03 CEST 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.30.0-1
- Update to latest upstream 0.30.0 (fixes rhbz#1966363)
- Fix license (internal/jwx is licensed under MIT license)

* Fri May 28 17:03:56 CEST 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.29.3-1
- Update to latest upstream 0.29.3 (fixes rhbz#1965613)

* Mon May 10 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.28.0-1
- Update to latest upstream 0.28.0 (fixes rhbz#1954091)

* Sat Mar 13 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.27.1-2
- Fix failing test on 32-bit architectures

* Sat Mar 13 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.27.1-1
- Update to latest upstream 0.27.1 (fixes #1936740)

* Tue Jan 26 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.26.0-2
- Remove dependency on github.com/wasmerio/go-ext-wasm (Fixes #1919476)
- Use upstream fix for Go 1.16 compatibility

* Thu Jan 21 2021 Olivier Lemasle <o.lemasle@gmail.com> - 0.26.0-1
- Update to latest upstream 0.26 (note: wasm disabled)

* Tue Oct 27 2020 Olivier Lemasle <o.lemasle@gmail.com> - 0.24.0-2
- Fix failing tests on 32-bit architectures
- Make telemetry service opt-out
- Fix version output

* Tue Oct 27 2020 Olivier Lemasle <o.lemasle@gmail.com> - 0.24.0-1
- Update to latest upstream 0.24

* Tue Apr 07 08:15:00 CEST 2020 Olivier Lemasle <o.lemasle@gmail.com> - 0.18.0-1
- Initial package