From 9c0007fb1d787b42d00e40ead6fb67f1c12128b4 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Fri, 6 Sep 2024 11:39:23 +0300 Subject: [PATCH] [#115] apemanager: Fix type getters * Add type instance check for nil to avoid panic by accessing fields. Signed-off-by: Airat Arifullin --- acl/types.go | 8 +++++++ ape/types.go | 8 +++++++ apemanager/types.go | 52 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/acl/types.go b/acl/types.go index b42528bd..960d8c96 100644 --- a/acl/types.go +++ b/acl/types.go @@ -330,10 +330,18 @@ func (bt *BearerTokenBody) SetEACL(v *Table) { } func (t *APEOverride) GetTarget() *ape.ChainTarget { + if t == nil { + return nil + } + return t.target } func (t *APEOverride) GetChains() []*ape.Chain { + if t == nil { + return nil + } + return t.chains } diff --git a/ape/types.go b/ape/types.go index 935a5ea3..467a4412 100644 --- a/ape/types.go +++ b/ape/types.go @@ -53,6 +53,10 @@ func (c *Chain) SetKind(kind chainKind) { } func (c *Chain) GetKind() chainKind { + if c == nil { + return nil + } + return c.kind } @@ -67,5 +71,9 @@ func (c *ChainRaw) SetRaw(raw []byte) { } func (c *ChainRaw) GetRaw() []byte { + if c == nil { + return nil + } + return c.Raw } diff --git a/apemanager/types.go b/apemanager/types.go index 21edf850..b6c39125 100644 --- a/apemanager/types.go +++ b/apemanager/types.go @@ -16,6 +16,10 @@ func (r *AddChainRequest) SetBody(body *AddChainRequestBody) { } func (r *AddChainRequest) GetBody() *AddChainRequestBody { + if r == nil { + return nil + } + return r.body } @@ -30,6 +34,10 @@ func (rb *AddChainRequestBody) SetTarget(target *ape.ChainTarget) { } func (rb *AddChainRequestBody) GetTarget() *ape.ChainTarget { + if rb == nil { + return nil + } + return rb.target } @@ -38,6 +46,10 @@ func (rb *AddChainRequestBody) SetChain(chain *ape.Chain) { } func (rb *AddChainRequestBody) GetChain() *ape.Chain { + if rb == nil { + return nil + } + return rb.chain } @@ -52,6 +64,10 @@ func (r *AddChainResponse) SetBody(body *AddChainResponseBody) { } func (r *AddChainResponse) GetBody() *AddChainResponseBody { + if r == nil { + return nil + } + return r.body } @@ -64,6 +80,10 @@ func (rb *AddChainResponseBody) SetChainID(chainID []byte) { } func (rb *AddChainResponseBody) GetChainID() []byte { + if rb == nil { + return nil + } + return rb.chainID } @@ -78,6 +98,10 @@ func (r *RemoveChainRequest) SetBody(body *RemoveChainRequestBody) { } func (r *RemoveChainRequest) GetBody() *RemoveChainRequestBody { + if r == nil { + return nil + } + return r.body } @@ -92,6 +116,10 @@ func (rb *RemoveChainRequestBody) SetTarget(target *ape.ChainTarget) { } func (rb *RemoveChainRequestBody) GetTarget() *ape.ChainTarget { + if rb == nil { + return nil + } + return rb.target } @@ -100,6 +128,10 @@ func (rb *RemoveChainRequestBody) SetChainID(chainID []byte) { } func (rb *RemoveChainRequestBody) GetChainID() []byte { + if rb == nil { + return nil + } + return rb.chainID } @@ -116,6 +148,10 @@ func (r *RemoveChainResponse) SetBody(body *RemoveChainResponseBody) { } func (r *RemoveChainResponse) GetBody() *RemoveChainResponseBody { + if r == nil { + return nil + } + return r.body } @@ -130,6 +166,10 @@ func (r *ListChainsRequest) SetBody(body *ListChainsRequestBody) { } func (r *ListChainsRequest) GetBody() *ListChainsRequestBody { + if r == nil { + return nil + } + return r.body } @@ -142,6 +182,10 @@ func (rb *ListChainsRequestBody) SetTarget(target *ape.ChainTarget) { } func (rb *ListChainsRequestBody) GetTarget() *ape.ChainTarget { + if rb == nil { + return nil + } + return rb.target } @@ -156,6 +200,10 @@ func (r *ListChainsResponse) SetBody(body *ListChainsResponseBody) { } func (r *ListChainsResponse) GetBody() *ListChainsResponseBody { + if r == nil { + return nil + } + return r.body } @@ -170,5 +218,9 @@ func (r *ListChainsResponseBody) SetChains(chains []*ape.Chain) { } func (r *ListChainsResponseBody) GetChains() []*ape.Chain { + if r == nil { + return nil + } + return r.chains }