-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vivek Singh <[email protected]>
- Loading branch information
Vivek Singh
committed
Feb 2, 2021
1 parent
3bc3121
commit ea48e37
Showing
4 changed files
with
336 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
182 changes: 91 additions & 91 deletions
182
components/automate-gateway/handler/infra_proxy/clients.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,126 @@ | ||
package infra_proxy | ||
|
||
import ( | ||
"context" | ||
"context" | ||
|
||
gwreq "github.com/chef/automate/api/external/infra_proxy/request" | ||
gwres "github.com/chef/automate/api/external/infra_proxy/response" | ||
infra_req "github.com/chef/automate/api/interservice/infra_proxy/request" | ||
infra_res "github.com/chef/automate/api/interservice/infra_proxy/response" | ||
gwreq "github.com/chef/automate/api/external/infra_proxy/request" | ||
gwres "github.com/chef/automate/api/external/infra_proxy/response" | ||
infra_req "github.com/chef/automate/api/interservice/infra_proxy/request" | ||
infra_res "github.com/chef/automate/api/interservice/infra_proxy/response" | ||
) | ||
|
||
// GetClients fetches an array of existing clients | ||
func (a *InfraProxyServer) GetClients(ctx context.Context, r *gwreq.Clients) (*gwres.Clients, error) { | ||
req := &infra_req.Clients{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
} | ||
res, err := a.client.GetClients(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := &infra_req.Clients{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
} | ||
res, err := a.client.GetClients(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &gwres.Clients{ | ||
Clients: fromUpstreamClients(res.Clients), | ||
}, nil | ||
return &gwres.Clients{ | ||
Clients: fromUpstreamClients(res.Clients), | ||
}, nil | ||
} | ||
|
||
// GetClient fetches an infra client details | ||
func (a *InfraProxyServer) GetClient(ctx context.Context, r *gwreq.Client) (*gwres.Client, error) { | ||
req := &infra_req.Client{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
} | ||
res, err := a.client.GetClient(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := &infra_req.Client{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
} | ||
res, err := a.client.GetClient(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &gwres.Client{ | ||
Name: res.GetName(), | ||
ClientName: res.GetClientName(), | ||
OrgName: res.GetOrgName(), | ||
Validator: res.GetValidator(), | ||
JsonClass: res.GetJsonClass(), | ||
ChefType: res.GetChefType(), | ||
ClientKey: &gwres.ClientAccessKey{ | ||
Name: res.GetClientKey().GetName(), | ||
ExpirationDate: res.GetClientKey().GetExpirationDate(), | ||
PublicKey: res.GetClientKey().GetPublicKey(), | ||
}, | ||
}, nil | ||
return &gwres.Client{ | ||
Name: res.GetName(), | ||
ClientName: res.GetClientName(), | ||
OrgName: res.GetOrgName(), | ||
Validator: res.GetValidator(), | ||
JsonClass: res.GetJsonClass(), | ||
ChefType: res.GetChefType(), | ||
ClientKey: &gwres.ClientAccessKey{ | ||
Name: res.GetClientKey().GetName(), | ||
ExpirationDate: res.GetClientKey().GetExpirationDate(), | ||
PublicKey: res.GetClientKey().GetPublicKey(), | ||
}, | ||
}, nil | ||
} | ||
|
||
// CreateClient creates an infra client | ||
func (a *InfraProxyServer) CreateClient(ctx context.Context, r *gwreq.CreateClient) (*gwres.CreateClient, error) { | ||
req := &infra_req.CreateClient{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
Validator: r.Validator, | ||
CreateKey: r.CreateKey, | ||
} | ||
res, err := a.client.CreateClient(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := &infra_req.CreateClient{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
Validator: r.Validator, | ||
CreateKey: r.CreateKey, | ||
} | ||
res, err := a.client.CreateClient(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &gwres.CreateClient{ | ||
Name: res.GetName(), | ||
ClientKey: &gwres.ClientKey{ | ||
Name: res.GetClientKey().GetName(), | ||
PublicKey: res.GetClientKey().GetPublicKey(), | ||
ExpirationDate: res.GetClientKey().GetExpirationDate(), | ||
PrivateKey: res.GetClientKey().GetPrivateKey(), | ||
}, | ||
}, nil | ||
return &gwres.CreateClient{ | ||
Name: res.GetName(), | ||
ClientKey: &gwres.ClientKey{ | ||
Name: res.GetClientKey().GetName(), | ||
PublicKey: res.GetClientKey().GetPublicKey(), | ||
ExpirationDate: res.GetClientKey().GetExpirationDate(), | ||
PrivateKey: res.GetClientKey().GetPrivateKey(), | ||
}, | ||
}, nil | ||
} | ||
|
||
// DeleteClient deletes an infra client | ||
func (a *InfraProxyServer) DeleteClient(ctx context.Context, r *gwreq.Client) (*gwres.Client, error) { | ||
req := &infra_req.Client{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
} | ||
res, err := a.client.DeleteClient(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := &infra_req.Client{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
} | ||
res, err := a.client.DeleteClient(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &gwres.Client{ | ||
Name: res.GetName(), | ||
}, nil | ||
return &gwres.Client{ | ||
Name: res.GetName(), | ||
}, nil | ||
} | ||
|
||
// ResetClientKey resets an infra client key | ||
func (a *InfraProxyServer) ResetClientKey(ctx context.Context, r *gwreq.ClientKey) (*gwres.ClientKey, error) { | ||
req := &infra_req.ClientKey{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
Key: r.Key, | ||
} | ||
res, err := a.client.ResetClientKey(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := &infra_req.ClientKey{ | ||
OrgId: r.OrgId, | ||
ServerId: r.ServerId, | ||
Name: r.Name, | ||
Key: r.Key, | ||
} | ||
res, err := a.client.ResetClientKey(ctx, req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &gwres.ClientKey{ | ||
Name: res.GetName(), | ||
PrivateKey: res.GetPrivateKey(), | ||
}, nil | ||
return &gwres.ClientKey{ | ||
Name: res.GetName(), | ||
PrivateKey: res.GetPrivateKey(), | ||
}, nil | ||
} | ||
|
||
func fromUpstreamClients(clients []*infra_res.ClientListItem) []*gwres.ClientListItem { | ||
ts := make([]*gwres.ClientListItem, len(clients)) | ||
ts := make([]*gwres.ClientListItem, len(clients)) | ||
|
||
for i, c := range clients { | ||
ts[i] = &gwres.ClientListItem{ | ||
Name: c.GetName(), | ||
} | ||
} | ||
for i, c := range clients { | ||
ts[i] = &gwres.ClientListItem{ | ||
Name: c.GetName(), | ||
} | ||
} | ||
|
||
return ts | ||
return ts | ||
} |
Oops, something went wrong.