Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add tome uploader #588

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

alexcote1
Copy link
Collaborator

What type of PR is this?

What this PR does / why we need it:

adds CLI app to upload tomes

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (88fcaa4) 71.14% compared to head (5734982) 71.14%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #588   +/-   ##
=======================================
  Coverage   71.14%   71.14%           
=======================================
  Files         147      147           
  Lines       10312    10312           
=======================================
  Hits         7336     7336           
  Misses       2797     2797           
  Partials      179      179           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hulto
Copy link
Collaborator

hulto commented Feb 14, 2024

Fixes #465

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you delete the "cats"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk I kindve like them...

@KCarretto KCarretto self-requested a review February 16, 2024 15:35
"realm.pub/tavern/cli/auth"
)

type Metadata struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just import these types from "realm.pub/tavern/tomes"

// main function to run the application.
func main() {
// Setup
basedir := os.Getenv("basedir")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "BASEDIR"

if basedir == "" {
basedir = "tomes"
}
endpoint := os.Getenv("endpoint")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "ENDPOINT"

} else {
graphqlEndpoint = endpoint + "/graphql"
}
cookie := os.Getenv("cookie")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "AUTH_COOKIE"

if err != nil {
panic(err)
}
cookie = token.String()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling token.String() will return the redacted message. You need to cast it to a string instead e.g. string(token).

Instead, prefer using token.Authenticate(req) on your http requests

escapedEldritchContent = strings.ReplaceAll(escapedEldritchContent, "\"", "\\\"")
escapedEldritchContent = strings.ReplaceAll(escapedEldritchContent, "\n", "\\n")

// Create files first and collect their IDs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Commented code

}

// processTomeDirectory reads files in a tome directory and prepares them for upload.
func processTomeDirectory(fs []fs.DirEntry, dirName string) (Metadata, string, []File, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can likely reuse some functionality from the "realm.pub/tavern/tomes" package here

}
}
`, metadata.Name, metadata.Description, metadata.Author, metadata.SupportModel, metadata.Tactic, paramDefsJSONString, escapedEldritchContent)
fmt.Println(createTomeMutation)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove println

req.Header.Set("Cookie", cookie)

// Create a new HTTP client and send the request
client := &http.Client{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using http.DefaultClient

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk I kindve like them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants