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

Fetch remote topo #1622

Closed
wants to merge 6 commits into from
Closed

Conversation

friday963
Copy link
Contributor

@friday963
Copy link
Contributor Author

Integration testing I conducted

utils/http.go Outdated
return err
}
if resp.StatusCode != 200 {
return errors.New("URL does not exist")
Copy link
Collaborator

@steiler steiler Oct 9, 2023

Choose a reason for hiding this comment

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

There are may other http status codes, that have different meanings, other then "URL does not exist".
The returned error should account for that.
Probably use https://pkg.go.dev/net/http#StatusText

Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally I'm actually seeing that we already have the http download functions available.
Check out CopyFileContents https://github.com/srl-labs/containerlab/blob/main/utils/file.go#L86

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid point on the status code. As for the CopyFileConents, I tried to implement that originally but was not able to get it to work for the remote file contents. I'll re-explore and see if I can get to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use copy method.

utils/http.go Outdated

}

func GetFileName(url string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably use https://pkg.go.dev/path#Base.

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually this is also available under utils/file.go -> FilenameForURL
https://github.com/srl-labs/containerlab/blob/main/utils/file.go#L259

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use FilenameForURL.

}

func IsGitHubURL(url string) bool {
return strings.Contains(url, "github")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This contains in my view is too broad. since also a "raw.githubusercontent.com" url would match.
In cmd/root.go you use this in the switch and consecutively apply the GetRawUrl. Which then does the conversion.
although that would check for "github.com" it should probably be more kind of "consistent".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I'm grasping what you'd like to see from this method.
You mentioned that it would match on raw.githubusercontent.com and you're right. I had planned on it matching on either a generic github.com or the raw.github path to offer flexibility to the end user. It then proceeds to that GetRawURL method where it only converts it if its a generic github.com url else it returns the url without converting anything.
How would you envision this changing?

@steiler
Copy link
Collaborator

steiler commented Oct 9, 2023

@hellt we should probably, when this is in shape, merge this and #1414 and continue from there. Opinion?

@hellt
Copy link
Member

hellt commented Oct 9, 2023

@steiler my idea was that this should solve all artifacts retrieval, both topo file as well as all linked artifacts like license, binds, startup-configs, etc.

@steiler
Copy link
Collaborator

steiler commented Oct 9, 2023

yes, and e.g. the general license retrieval is already implemented in #1414 so they sould be merged and finalized altogether

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Merging #1622 (916f167) into main (2c36cc8) will increase coverage by 0.46%.
Report is 33 commits behind head on main.
The diff coverage is 61.81%.

❗ Current head 916f167 differs from pull request most recent head 5411f33. Consider uploading reports for the commit 5411f33 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1622      +/-   ##
==========================================
+ Coverage   48.55%   49.02%   +0.46%     
==========================================
  Files         133      136       +3     
  Lines       12779    13136     +357     
==========================================
+ Hits         6205     6440     +235     
- Misses       5870     5985     +115     
- Partials      704      711       +7     
Files Coverage Δ
utils/http.go 78.57% <78.57%> (ø)
cmd/root.go 60.00% <7.69%> (-8.75%) ⬇️

... and 35 files with indirect coverage changes

@friday963 friday963 closed this Oct 12, 2023
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.

3 participants