From d19d2157989cb4900b250bb928f4c263c17758c6 Mon Sep 17 00:00:00 2001 From: Arstanaly Rysbekov Date: Mon, 25 Sep 2023 10:53:56 +0200 Subject: [PATCH] WIP: start implementing azure web app logs retrieval --- cmd/kosli/snapshotAzureFunctions.go | 4 ++++ internal/azure/azure_functions.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cmd/kosli/snapshotAzureFunctions.go b/cmd/kosli/snapshotAzureFunctions.go index 413154e4f..1faf7bfb2 100644 --- a/cmd/kosli/snapshotAzureFunctions.go +++ b/cmd/kosli/snapshotAzureFunctions.go @@ -65,7 +65,11 @@ func (o *snapshotAzureFunctionsOptions) run(args []string) error { for _, host := range webapp.Properties.EnabledHostNames { fmt.Printf("Webapp host: %s\n", *host) } + } + err = o.azureCredentials.GetDockerLogs() + if err != nil { + return err } // envName := args[0] diff --git a/internal/azure/azure_functions.go b/internal/azure/azure_functions.go index 757cddcda..1441f22f4 100644 --- a/internal/azure/azure_functions.go +++ b/internal/azure/azure_functions.go @@ -2,6 +2,8 @@ package azure import ( "context" + "io" + "net/http" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2" @@ -40,3 +42,27 @@ func (staticCreds *AzureStaticCredentials) GetWebAppsInfo() ([]*armappservice.Si } return webAppsInfo, nil } + +func (staticCreds *AzureStaticCredentials) GetDockerLogs() error { + client := &http.Client{} + + req, err := http.NewRequest("GET", "https://tsha256.scm.azurewebsites.net/api/vfs/LogFiles/2023_09_14_10-30-0-8_docker.log", nil) + if err != nil { + return err + } + req.SetBasicAuth(staticCreds.ClientId, staticCreds.ClientSecret) + resp, err := client.Do(req) + if err != nil { + return err + } + if resp.Body != nil { + defer resp.Body.Close() + } + body, err := io.ReadAll(resp.Body) + if err != nil { + return err + } + println(string(body)) + + return nil +}