mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-17 18:41:41 +02:00
remove ids from policy creation
This commit is contained in:
@ -707,10 +707,6 @@ components:
|
|||||||
PolicyRuleMinimum:
|
PolicyRuleMinimum:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
|
||||||
description: Policy rule ID
|
|
||||||
type: string
|
|
||||||
example: ch8i4ug6lnn4g9hqv7mg
|
|
||||||
name:
|
name:
|
||||||
description: Policy rule name identifier
|
description: Policy rule name identifier
|
||||||
type: string
|
type: string
|
||||||
@ -772,6 +768,31 @@ components:
|
|||||||
- end
|
- end
|
||||||
|
|
||||||
PolicyRuleUpdate:
|
PolicyRuleUpdate:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/PolicyRuleMinimum'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
description: Policy rule ID
|
||||||
|
type: string
|
||||||
|
example: ch8i4ug6lnn4g9hqv7mg
|
||||||
|
sources:
|
||||||
|
description: Policy rule source group IDs
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: "ch8i4ug6lnn4g9hqv797"
|
||||||
|
destinations:
|
||||||
|
description: Policy rule destination group IDs
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: "ch8i4ug6lnn4g9h7v7m0"
|
||||||
|
required:
|
||||||
|
- sources
|
||||||
|
- destinations
|
||||||
|
|
||||||
|
PolicyRuleCreate:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/PolicyRuleMinimum'
|
- $ref: '#/components/schemas/PolicyRuleMinimum'
|
||||||
- type: object
|
- type: object
|
||||||
@ -796,6 +817,10 @@ components:
|
|||||||
- $ref: '#/components/schemas/PolicyRuleMinimum'
|
- $ref: '#/components/schemas/PolicyRuleMinimum'
|
||||||
- type: object
|
- type: object
|
||||||
properties:
|
properties:
|
||||||
|
id:
|
||||||
|
description: Policy rule ID
|
||||||
|
type: string
|
||||||
|
example: ch8i4ug6lnn4g9hqv7mg
|
||||||
sources:
|
sources:
|
||||||
description: Policy rule source group IDs
|
description: Policy rule source group IDs
|
||||||
type: array
|
type: array
|
||||||
@ -812,10 +837,6 @@ components:
|
|||||||
PolicyMinimum:
|
PolicyMinimum:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
|
||||||
description: Policy ID
|
|
||||||
type: string
|
|
||||||
example: ch8i4ug6lnn4g9hqv7mg
|
|
||||||
name:
|
name:
|
||||||
description: Policy name identifier
|
description: Policy name identifier
|
||||||
type: string
|
type: string
|
||||||
@ -830,7 +851,6 @@ components:
|
|||||||
example: true
|
example: true
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- description
|
|
||||||
- enabled
|
- enabled
|
||||||
PolicyUpdate:
|
PolicyUpdate:
|
||||||
allOf:
|
allOf:
|
||||||
@ -850,11 +870,33 @@ components:
|
|||||||
$ref: '#/components/schemas/PolicyRuleUpdate'
|
$ref: '#/components/schemas/PolicyRuleUpdate'
|
||||||
required:
|
required:
|
||||||
- rules
|
- rules
|
||||||
|
PolicyCreate:
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/components/schemas/PolicyMinimum'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
source_posture_checks:
|
||||||
|
description: Posture checks ID's applied to policy source groups
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: "chacdk86lnnboviihd70"
|
||||||
|
rules:
|
||||||
|
description: Policy rule object for policy UI editor
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/components/schemas/PolicyRuleUpdate'
|
||||||
|
required:
|
||||||
|
- rules
|
||||||
Policy:
|
Policy:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/PolicyMinimum'
|
- $ref: '#/components/schemas/PolicyMinimum'
|
||||||
- type: object
|
- type: object
|
||||||
properties:
|
properties:
|
||||||
|
id:
|
||||||
|
description: Policy ID
|
||||||
|
type: string
|
||||||
|
example: ch8i4ug6lnn4g9hqv7mg
|
||||||
source_posture_checks:
|
source_posture_checks:
|
||||||
description: Posture checks ID's applied to policy source groups
|
description: Posture checks ID's applied to policy source groups
|
||||||
type: array
|
type: array
|
||||||
@ -2274,7 +2316,7 @@ paths:
|
|||||||
content:
|
content:
|
||||||
'application/json':
|
'application/json':
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/PolicyUpdate'
|
$ref: '#/components/schemas/PolicyCreate'
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: A Policy object
|
description: A Policy object
|
||||||
|
@ -737,7 +737,7 @@ type PersonalAccessTokenRequest struct {
|
|||||||
// Policy defines model for Policy.
|
// Policy defines model for Policy.
|
||||||
type Policy struct {
|
type Policy struct {
|
||||||
// Description Policy friendly description
|
// Description Policy friendly description
|
||||||
Description string `json:"description"`
|
Description *string `json:"description,omitempty"`
|
||||||
|
|
||||||
// Enabled Policy status
|
// Enabled Policy status
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
@ -755,16 +755,31 @@ type Policy struct {
|
|||||||
SourcePostureChecks []string `json:"source_posture_checks"`
|
SourcePostureChecks []string `json:"source_posture_checks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PolicyMinimum defines model for PolicyMinimum.
|
// PolicyCreate defines model for PolicyCreate.
|
||||||
type PolicyMinimum struct {
|
type PolicyCreate struct {
|
||||||
// Description Policy friendly description
|
// Description Policy friendly description
|
||||||
Description string `json:"description"`
|
Description *string `json:"description,omitempty"`
|
||||||
|
|
||||||
// Enabled Policy status
|
// Enabled Policy status
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
|
|
||||||
// Id Policy ID
|
// Name Policy name identifier
|
||||||
Id *string `json:"id,omitempty"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// Rules Policy rule object for policy UI editor
|
||||||
|
Rules []PolicyRuleUpdate `json:"rules"`
|
||||||
|
|
||||||
|
// SourcePostureChecks Posture checks ID's applied to policy source groups
|
||||||
|
SourcePostureChecks *[]string `json:"source_posture_checks,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PolicyMinimum defines model for PolicyMinimum.
|
||||||
|
type PolicyMinimum struct {
|
||||||
|
// Description Policy friendly description
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
|
||||||
|
// Enabled Policy status
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
|
||||||
// Name Policy name identifier
|
// Name Policy name identifier
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -826,9 +841,6 @@ type PolicyRuleMinimum struct {
|
|||||||
// Enabled Policy rule status
|
// Enabled Policy rule status
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
|
|
||||||
// Id Policy rule ID
|
|
||||||
Id *string `json:"id,omitempty"`
|
|
||||||
|
|
||||||
// Name Policy rule name identifier
|
// Name Policy rule name identifier
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
@ -893,14 +905,11 @@ type PolicyRuleUpdateProtocol string
|
|||||||
// PolicyUpdate defines model for PolicyUpdate.
|
// PolicyUpdate defines model for PolicyUpdate.
|
||||||
type PolicyUpdate struct {
|
type PolicyUpdate struct {
|
||||||
// Description Policy friendly description
|
// Description Policy friendly description
|
||||||
Description string `json:"description"`
|
Description *string `json:"description,omitempty"`
|
||||||
|
|
||||||
// Enabled Policy status
|
// Enabled Policy status
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
|
|
||||||
// Id Policy ID
|
|
||||||
Id *string `json:"id,omitempty"`
|
|
||||||
|
|
||||||
// Name Policy name identifier
|
// Name Policy name identifier
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
@ -1299,7 +1308,7 @@ type PutApiPeersPeerIdJSONRequestBody = PeerRequest
|
|||||||
type PostApiPoliciesJSONRequestBody = PolicyUpdate
|
type PostApiPoliciesJSONRequestBody = PolicyUpdate
|
||||||
|
|
||||||
// PutApiPoliciesPolicyIdJSONRequestBody defines body for PutApiPoliciesPolicyId for application/json ContentType.
|
// PutApiPoliciesPolicyIdJSONRequestBody defines body for PutApiPoliciesPolicyId for application/json ContentType.
|
||||||
type PutApiPoliciesPolicyIdJSONRequestBody = PolicyUpdate
|
type PutApiPoliciesPolicyIdJSONRequestBody = PolicyCreate
|
||||||
|
|
||||||
// PostApiPostureChecksJSONRequestBody defines body for PostApiPostureChecks for application/json ContentType.
|
// PostApiPostureChecksJSONRequestBody defines body for PostApiPostureChecks for application/json ContentType.
|
||||||
type PostApiPostureChecksJSONRequestBody = PostureCheckUpdate
|
type PostApiPostureChecksJSONRequestBody = PostureCheckUpdate
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server"
|
"github.com/netbirdio/netbird/management/server"
|
||||||
nbgroup "github.com/netbirdio/netbird/management/server/group"
|
nbgroup "github.com/netbirdio/netbird/management/server/group"
|
||||||
"github.com/netbirdio/netbird/management/server/http/api"
|
"github.com/netbirdio/netbird/management/server/http/api"
|
||||||
@ -120,16 +121,21 @@ func (h *Policies) savePolicy(w http.ResponseWriter, r *http.Request, accountID
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
description := ""
|
||||||
|
if req.Description != nil {
|
||||||
|
description = *req.Description
|
||||||
|
}
|
||||||
|
|
||||||
policy := &server.Policy{
|
policy := &server.Policy{
|
||||||
ID: policyID,
|
ID: policyID,
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Enabled: req.Enabled,
|
Enabled: req.Enabled,
|
||||||
Description: req.Description,
|
Description: description,
|
||||||
}
|
}
|
||||||
for _, rule := range req.Rules {
|
for _, rule := range req.Rules {
|
||||||
var ruleID string
|
var ruleID string
|
||||||
if rule.Id != nil {
|
if rule.Id != nil && policyID != "" {
|
||||||
ruleID = *rule.Id
|
ruleID = *rule.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +322,7 @@ func toPolicyResponse(groups []*nbgroup.Group, policy *server.Policy) *api.Polic
|
|||||||
ap := &api.Policy{
|
ap := &api.Policy{
|
||||||
Id: &policy.ID,
|
Id: &policy.ID,
|
||||||
Name: policy.Name,
|
Name: policy.Name,
|
||||||
Description: policy.Description,
|
Description: &policy.Description,
|
||||||
Enabled: policy.Enabled,
|
Enabled: policy.Enabled,
|
||||||
SourcePostureChecks: policy.SourcePostureChecks,
|
SourcePostureChecks: policy.SourcePostureChecks,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user