Skip to content

Commit

Permalink
Create server API - create the chef server using the webui key (#6376)
Browse files Browse the repository at this point in the history
* added API chanegs for adding the chef server with webui key

Signed-off-by: Vinay Sharma <vsharma@chef.io>

* added changes for the validation and test cases

Signed-off-by: Vinay Sharma <vsharma@chef.io>
  • Loading branch information
vinay033 committed May 2, 2022
1 parent 104453a commit 9730fdd
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 62 deletions.
2 changes: 2 additions & 0 deletions api/external/infra_proxy/infra_proxy.pb.policy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/external/infra_proxy/infra_proxy.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 36 additions & 25 deletions api/external/infra_proxy/request/servers.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/external/infra_proxy/request/servers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ message CreateServer {
string fqdn = 3;
// Chef Infra Server IP address.
string ip_address = 4;
// Chef Infra Server Webui key.
string webui_key = 5;
}

message UpdateServer {
Expand Down
64 changes: 37 additions & 27 deletions api/interservice/infra_proxy/request/servers.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/interservice/infra_proxy/request/servers.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ message CreateServer {
string fqdn = 3;
// Chef Infra Server IP address.
string ip_address = 4;
// Chef Infra Server Webui key.
string webui_key = 5;
}

message UpdateServer {
Expand Down
4 changes: 4 additions & 0 deletions components/automate-gateway/api/infra_proxy.pb.swagger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions components/automate-gateway/handler/infra_proxy/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package infra_proxy

import (
"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"
Expand Down Expand Up @@ -44,6 +45,7 @@ func (a *InfraProxyServer) CreateServer(ctx context.Context, r *gwreq.CreateServ
Name: r.Name,
Fqdn: r.Fqdn,
IpAddress: r.IpAddress,
WebuiKey: r.WebuiKey,
}
res, err := a.client.CreateServer(ctx, req)
if err != nil {
Expand Down
22 changes: 19 additions & 3 deletions components/infra-proxy-service/server/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"io/ioutil"

"github.com/chef/automate/api/external/common/query"
secrets "github.com/chef/automate/api/external/secrets"
"github.com/chef/automate/api/interservice/infra_proxy/request"
"github.com/chef/automate/api/interservice/infra_proxy/response"
"github.com/chef/automate/components/infra-proxy-service/service"
Expand All @@ -27,8 +29,9 @@ func (s *Server) CreateServer(ctx context.Context, req *request.CreateServer) (*
Target: "server",
Request: *req,
Rules: validation.Rules{
"Id": []string{"required"},
"Name": []string{"required"},
"Id": []string{"required"},
"Name": []string{"required"},
"WebuiKey": []string{"required"},
},
}).Validate()

Expand All @@ -40,6 +43,19 @@ func (s *Server) CreateServer(ctx context.Context, req *request.CreateServer) (*
return nil, errors.Wrap(err, "FQDN or IP required to add the server.")
}

// TODO: validate the new webui key
newSecret := &secrets.Secret{
Name: "infra-proxy-service-webui-key",
Type: "chef-server",
Data: []*query.Kv{
{Key: "key", Value: req.WebuiKey},
},
}
credential, err := s.service.Secrets.Create(ctx, newSecret)
if err != nil {
return nil, err
}

// commenting this code because sometimes chef-services are down that time we can't able to check the server status and not able to add or update the server.
/*
serverHost := req.GetFqdn()
Expand All @@ -53,7 +69,7 @@ func (s *Server) CreateServer(ctx context.Context, req *request.CreateServer) (*
}
*/

server, err := s.service.Storage.StoreServer(ctx, req.Id, req.Name, req.Fqdn, req.IpAddress)
server, err := s.service.Storage.StoreServer(ctx, req.Id, req.Name, req.Fqdn, req.IpAddress, credential.Id)
if err != nil {
return nil, service.ParseStorageError(err, *req, "server")
}
Expand Down
Loading

0 comments on commit 9730fdd

Please sign in to comment.