-
Notifications
You must be signed in to change notification settings - Fork 612
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: Matthis Holleville <matthish29@gmail.com>
- Loading branch information
1 parent
49e120c
commit eb7cbaf
Showing
8 changed files
with
148 additions
and
100 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
json "encoding/json" | ||
|
||
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/analysis" | ||
) | ||
|
||
func (h *handler) Analyze(ctx context.Context, i *schemav1.AnalyzeRequest) ( | ||
*schemav1.AnalyzeResponse, | ||
error, | ||
) { | ||
if i.Output == "" { | ||
i.Output = "json" | ||
} | ||
|
||
if i.Backend == "" { | ||
i.Backend = "openai" | ||
} | ||
|
||
if int(i.MaxConcurrency) == 0 { | ||
i.MaxConcurrency = 10 | ||
} | ||
|
||
config, err := analysis.NewAnalysis( | ||
i.Backend, | ||
i.Language, | ||
i.Filters, | ||
i.Namespace, | ||
i.Nocache, | ||
i.Explain, | ||
int(i.MaxConcurrency), | ||
) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
config.RunAnalysis() | ||
|
||
if i.Explain { | ||
err := config.GetAIResults(i.Output, i.Anonymize) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
} | ||
|
||
out, err := config.PrintOutput(i.Output) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
var obj schemav1.AnalyzeResponse | ||
|
||
err = json.Unmarshal(out, &obj) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
|
||
return &obj, nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/cache" | ||
) | ||
|
||
func (h *handler) AddConfig(ctx context.Context, i *schemav1.ConfigRequest) (*schemav1.ConfigResponse, error, | ||
) { | ||
if i.Cache.BucketName == "" || i.Cache.Region == "" { | ||
return nil, errors.New("BucketName & Region are required") | ||
} | ||
|
||
err := cache.AddCache(i.Cache.BucketName, i.Cache.Region) | ||
if err != nil { | ||
return &schemav1.ConfigResponse{}, err | ||
} | ||
|
||
return &schemav1.ConfigResponse{ | ||
Status: "Configuration updated.", | ||
}, nil | ||
} | ||
|
||
func (h *handler) RemoveConfig(ctx context.Context, i *schemav1.ConfigRequest) (*schemav1.ConfigResponse, error, | ||
) { | ||
err := cache.RemoveCache(i.Cache.BucketName) | ||
if err != nil { | ||
return &schemav1.ConfigResponse{}, err | ||
} | ||
|
||
return &schemav1.ConfigResponse{ | ||
Status: "Successfully removed the remote cache", | ||
}, nil | ||
} |
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,65 +1,9 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
json "encoding/json" | ||
|
||
rpc "buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go/schema/v1/schemav1grpc" | ||
schemav1 "buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbuffers/go/schema/v1" | ||
"github.com/k8sgpt-ai/k8sgpt/pkg/analysis" | ||
) | ||
|
||
type handler struct { | ||
rpc.UnimplementedServerServer | ||
} | ||
|
||
func (h *handler) Analyze(ctx context.Context, i *schemav1.AnalyzeRequest) ( | ||
*schemav1.AnalyzeResponse, | ||
error, | ||
) { | ||
if i.Output == "" { | ||
i.Output = "json" | ||
} | ||
|
||
if i.Backend == "" { | ||
i.Backend = "openai" | ||
} | ||
|
||
if int(i.MaxConcurrency) == 0 { | ||
i.MaxConcurrency = 10 | ||
} | ||
|
||
config, err := analysis.NewAnalysis( | ||
i.Backend, | ||
i.Language, | ||
i.Filters, | ||
i.Namespace, | ||
i.Nocache, | ||
i.Explain, | ||
int(i.MaxConcurrency), | ||
) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
config.RunAnalysis() | ||
|
||
if i.Explain { | ||
err := config.GetAIResults(i.Output, i.Anonymize) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
} | ||
|
||
out, err := config.PrintOutput(i.Output) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
var obj schemav1.AnalyzeResponse | ||
|
||
err = json.Unmarshal(out, &obj) | ||
if err != nil { | ||
return &schemav1.AnalyzeResponse{}, err | ||
} | ||
|
||
return &obj, nil | ||
} |