decouple bouncer dependencies: use go-cs-lib/pkg/ptr in apiclient (#2227)
This commit is contained in:
parent
e1400d28f1
commit
e5fe74ce77
|
@ -6,6 +6,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
|
"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||||
|
@ -102,10 +104,10 @@ func (s *DecisionsService) GetDecisionsFromGroups(decisionsGroups []*modelscapi.
|
||||||
partialDecisions[idx] = &models.Decision{
|
partialDecisions[idx] = &models.Decision{
|
||||||
Scenario: decisionsGroup.Scenario,
|
Scenario: decisionsGroup.Scenario,
|
||||||
Scope: decisionsGroup.Scope,
|
Scope: decisionsGroup.Scope,
|
||||||
Type: types.StrPtr(types.DecisionTypeBan),
|
Type: ptr.Of(types.DecisionTypeBan),
|
||||||
Value: decision.Value,
|
Value: decision.Value,
|
||||||
Duration: decision.Duration,
|
Duration: decision.Duration,
|
||||||
Origin: types.StrPtr(types.CAPIOrigin),
|
Origin: ptr.Of(types.CAPIOrigin),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decisions = append(decisions, partialDecisions...)
|
decisions = append(decisions, partialDecisions...)
|
||||||
|
@ -138,10 +140,10 @@ func (s *DecisionsService) FetchV3Decisions(ctx context.Context, url string) (*m
|
||||||
partialDecisions[idx] = &models.Decision{
|
partialDecisions[idx] = &models.Decision{
|
||||||
Scenario: &scenarioDeleted,
|
Scenario: &scenarioDeleted,
|
||||||
Scope: decisionsGroup.Scope,
|
Scope: decisionsGroup.Scope,
|
||||||
Type: types.StrPtr(types.DecisionTypeBan),
|
Type: ptr.Of(types.DecisionTypeBan),
|
||||||
Value: &decision,
|
Value: &decision,
|
||||||
Duration: &durationDeleted,
|
Duration: &durationDeleted,
|
||||||
Origin: types.StrPtr(types.CAPIOrigin),
|
Origin: ptr.Of(types.CAPIOrigin),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v2Decisions.Deleted = append(v2Decisions.Deleted, partialDecisions...)
|
v2Decisions.Deleted = append(v2Decisions.Deleted, partialDecisions...)
|
||||||
|
@ -210,7 +212,7 @@ func (s *DecisionsService) GetDecisionsFromBlocklist(ctx context.Context, blockl
|
||||||
Type: blocklist.Remediation,
|
Type: blocklist.Remediation,
|
||||||
Value: &decision,
|
Value: &decision,
|
||||||
Duration: blocklist.Duration,
|
Duration: blocklist.Duration,
|
||||||
Origin: types.StrPtr(types.ListOrigin),
|
Origin: ptr.Of(types.ListOrigin),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/crowdsecurity/go-cs-lib/pkg/ptr"
|
||||||
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
"github.com/crowdsecurity/go-cs-lib/pkg/version"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
|
"github.com/crowdsecurity/crowdsec/pkg/modelscapi"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -461,7 +461,7 @@ func TestDecisionsFromBlocklist(t *testing.T) {
|
||||||
Remediation: &tremediationBlocklist,
|
Remediation: &tremediationBlocklist,
|
||||||
Name: &tnameBlocklist,
|
Name: &tnameBlocklist,
|
||||||
Duration: &tdurationBlocklist,
|
Duration: &tdurationBlocklist,
|
||||||
}, types.StrPtr("Sun, 01 Jan 2023 01:01:01 GMT"))
|
}, ptr.Of("Sun, 01 Jan 2023 01:01:01 GMT"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.False(t, isModified)
|
assert.False(t, isModified)
|
||||||
_, isModified, err = newcli.Decisions.GetDecisionsFromBlocklist(context.Background(), &modelscapi.BlocklistLink{
|
_, isModified, err = newcli.Decisions.GetDecisionsFromBlocklist(context.Background(), &modelscapi.BlocklistLink{
|
||||||
|
@ -470,7 +470,7 @@ func TestDecisionsFromBlocklist(t *testing.T) {
|
||||||
Remediation: &tremediationBlocklist,
|
Remediation: &tremediationBlocklist,
|
||||||
Name: &tnameBlocklist,
|
Name: &tnameBlocklist,
|
||||||
Duration: &tdurationBlocklist,
|
Duration: &tdurationBlocklist,
|
||||||
}, types.StrPtr("Mon, 02 Jan 2023 01:01:01 GMT"))
|
}, ptr.Of("Mon, 02 Jan 2023 01:01:01 GMT"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.True(t, isModified)
|
assert.True(t, isModified)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue