-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
Fixes #465 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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...
"realm.pub/tavern/cli/auth" | ||
) | ||
|
||
type Metadata struct { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using http.DefaultClient
There was a problem hiding this comment.
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...
What type of PR is this?
What this PR does / why we need it:
adds CLI app to upload tomes