Skip to content

Commit

Permalink
Merge pull request #120 from section/deploy-better-integration
Browse files Browse the repository at this point in the history
parse package.json and section.config.json for better output, and replace logging pipeline
  • Loading branch information
AskAlice committed Jun 3, 2021
2 parents 9e011f0 + 6369011 commit 9306edf
Show file tree
Hide file tree
Showing 24 changed files with 523 additions and 328 deletions.
7 changes: 4 additions & 3 deletions api/api.go
Expand Up @@ -5,12 +5,13 @@ import (
"errors"
"fmt"
"io"
"log"
"net/http"
"net/url"
"runtime"
"time"

"github.com/rs/zerolog/log"

"github.com/section/sectionctl/version"
)

Expand Down Expand Up @@ -61,13 +62,13 @@ func request(ctx context.Context, method string, u url.URL, body io.Reader, head

req.Header.Add("section-token", Token)

log.Println("[DEBUG] Request URL:", method, req.URL)
log.Debug().Str("Request Method",method).Str("Request URL", req.URL.String()).Msg("Making Request")
for k, vs := range req.Header {
for _, v := range vs {
if k == "Section-Token" {
v = "********TOKEN HIDDEN********"
}
log.Printf("[DEBUG] Header: %s: %v\n", k, v)
log.Debug().Str(k,v).Msg("Header")
}
}
resp, err = client.Do(req)
Expand Down
11 changes: 6 additions & 5 deletions api/applications.go
Expand Up @@ -7,9 +7,10 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"time"

"github.com/rs/zerolog/log"
)

// App represents an application deployed on Section
Expand Down Expand Up @@ -240,7 +241,7 @@ func ApplicationEnvironmentModuleUpdate(accountID int, applicationID int, env st
if err != nil {
return fmt.Errorf("failed to encode json payload: %v", err)
}
log.Printf("[DEBUG] JSON payload: %s\n", b)
log.Debug().Msg(fmt.Sprintf(" JSON payload: %s\n", b))

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) // because these requests can take a long time to complete on Section's side
defer cancel()
Expand Down Expand Up @@ -331,7 +332,7 @@ func ApplicationStatus(accountID int, applicationID int, moduleName string) (as
return as, fmt.Errorf("could not read response body: %s", err)
}

log.Printf("[DEBUG] RESPONSE: %s\n", string(body))
log.Debug().Msg(fmt.Sprintf(" RESPONSE: %s\n", string(body)))

var responseBody struct {
Data struct {
Expand Down Expand Up @@ -375,7 +376,7 @@ func ApplicationLogs(accountID int, applicationID int, moduleName string, instan
// "endTimestamp": endTimestamp,
}

log.Printf("[DEBUG] requestData: %v\n", requestData.Variables)
log.Debug().Msg(fmt.Sprintf(" requestData: %v\n", requestData.Variables))

requestData.Query = "query Logs($moduleName: String!, $environmentId: Int!, $instanceName: String, $length: Int){logs(moduleName:$moduleName, environmentId:$environmentId, instanceName:$instanceName, length:$length){timestamp instanceName message type}}"

Expand All @@ -402,7 +403,7 @@ func ApplicationLogs(accountID int, applicationID int, moduleName string, instan
return al, fmt.Errorf("could not read response body: %s", err)
}

log.Printf("[DEBUG] RESPONSE: %s\n", string(body))
log.Debug().Msg(fmt.Sprintf(" RESPONSE: %s\n", string(body)))

var responseBody struct {
Data struct {
Expand Down
8 changes: 4 additions & 4 deletions commands/accounts.go
@@ -1,10 +1,10 @@
package commands

import (
"context"
"os"
"strconv"

"github.com/alecthomas/kong"
"github.com/section/sectionctl/api"
)

Expand All @@ -17,8 +17,8 @@ type AccountsCmd struct {
type AccountsListCmd struct{}

// Run executes the command
func (c *AccountsListCmd) Run(ctx context.Context) (err error) {
s := NewSpinner(ctx, "Looking up accounts")
func (c *AccountsListCmd) Run(cli *CLI, ctx *kong.Context,logWriters *LogWriters) (err error) {
s := NewSpinner("Looking up accounts", logWriters)
s.Start()

accounts, err := api.Accounts()
Expand All @@ -27,7 +27,7 @@ func (c *AccountsListCmd) Run(ctx context.Context) (err error) {
return err
}

table := NewTable(ctx, os.Stdout)
table := NewTable(cli, os.Stdout)
table.SetHeader([]string{"Account ID", "Account Name"})

for _, a := range accounts {
Expand Down

0 comments on commit 9306edf

Please sign in to comment.