From 34c4b9b87ecaa47ba948f3ab5badcdb3f45c8ac7 Mon Sep 17 00:00:00 2001 From: Samuel Lorch Date: Wed, 12 Apr 2023 20:24:27 +0200 Subject: [PATCH] Add Get Interface API --- internal/api/network/interfaces.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/api/network/interfaces.go b/internal/api/network/interfaces.go index 0b5656a..2cec456 100644 --- a/internal/api/network/interfaces.go +++ b/internal/api/network/interfaces.go @@ -22,6 +22,27 @@ func (f *Network) GetLinks(ctx context.Context, params struct{}) (GetLinksResult }, nil } +type GetInterfaceParameters struct { + ID string +} + +type GetInterfaceResult struct { + Name string `json:"name"` + definitions.Interface +} + +func (f *Network) GetInterface(ctx context.Context, params GetInterfaceParameters) (GetInterfaceResult, error) { + _, ok := f.ConfigManager.GetPendingConfig().Network.Interfaces[params.ID] + if !ok { + return GetInterfaceResult{}, fmt.Errorf("Interface does not Exist") + } + + return GetInterfaceResult{ + Name: params.ID, + Interface: f.ConfigManager.GetPendingConfig().Network.Interfaces[params.ID], + }, nil +} + type GetInterfacesResult struct { Interfaces map[string]definitions.Interface } @@ -33,7 +54,7 @@ func (f *Network) GetInterfaces(ctx context.Context, params struct{}) (GetInterf } type CreateInterfaceParameters struct { - Name string + Name string `json:"name"` definitions.Interface }