Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Send user agents with all our tools #1289

Merged
merged 1 commit into from
Aug 13, 2019
Merged

Conversation

lbonn
Copy link
Contributor

@lbonn lbonn commented Aug 9, 2019

No description provided.

@lbonn lbonn force-pushed the feat/OTA-3550/tools-user-agent branch 2 times, most recently from 202efc2 to ffc53f1 Compare August 9, 2019 17:06
@codecov-io
Copy link

codecov-io commented Aug 9, 2019

Codecov Report

Merging #1289 into master will decrease coverage by 0.1%.
The diff coverage is 95.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1289      +/-   ##
==========================================
- Coverage   79.32%   79.22%   -0.11%     
==========================================
  Files         175      175              
  Lines       10367    10379      +12     
==========================================
- Hits         8224     8223       -1     
- Misses       2143     2156      +13
Impacted Files Coverage Δ
src/libaktualizr/utilities/utils.h 93.33% <ø> (+2.42%) ⬆️
src/libaktualizr/http/httpclient.h 100% <ø> (ø) ⬆️
src/sota_tools/garage_push.cc 71.59% <100%> (+0.32%) ⬆️
src/sota_tools/garage_check.cc 59.67% <100%> (+0.66%) ⬆️
src/sota_tools/garage_deploy.cc 89.61% <100%> (+0.13%) ⬆️
src/libaktualizr/http/httpclient.cc 92.07% <100%> (-0.05%) ⬇️
src/sota_tools/ostree_object.cc 94.58% <100%> (+0.04%) ⬆️
src/libaktualizr/utilities/utils.cc 83.41% <93.75%> (+0.37%) ⬆️
src/libaktualizr/storage/sqlstorage_base.cc 78.37% <0%> (-2.03%) ⬇️
src/libaktualizr/uptane/directorrepository.cc 95.71% <0%> (-1.43%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fce6da4...41afadf. Read the comment docs.

Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me!


const auto resp = http.get(server + "/user_agent", HttpInterface::kNoLimit);
const auto app = resp.body.substr(0, resp.body.find('/'));
EXPECT_EQ(app, "Aktualizr");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you provide a brief comment to make it clear that you're testing the expected default here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!
Done.

curlEasySetoptWrapper(handle, CURLOPT_NOBODY, 1L);
curlEasySetoptWrapper(handle, CURLOPT_VERBOSE, 1L);
curlEasySetoptWrapper(handle, CURLOPT_SSL_VERIFYPEER, 0L);
CurlEasyWrapper curl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

@lbonn lbonn force-pushed the feat/OTA-3550/tools-user-agent branch from ffc53f1 to 41afadf Compare August 12, 2019 08:12
@@ -73,7 +61,7 @@ HttpClient::HttpClient(const std::vector<std::string>* extra_headers)
}
}
curlEasySetoptWrapper(curl, CURLOPT_HTTPHEADER, headers);
curlEasySetoptWrapper(curl, CURLOPT_USERAGENT, user_agent.c_str());
curlEasySetoptWrapper(curl, CURLOPT_USERAGENT, Utils::getUserAgent());
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might override the user agent header specified by an HttpClient user/client in extra_headers.
IMHO, statically predefined headers should be specified in a HTTP client factory configuration (which doesn't exist), so libaktualizr clients could specify desired mandatory headers in explicit way. Utils::set/getUserAgent() is an implicit API for libaktualizr clients/apps they need to be aware and set it before Aktualizr instantiation.
This is just my two cents and can be ignored since it will require more 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.

Yes, I agree this is not especially elegant. The main problem I had is that different garage tools are using some common code that instantiates an HttpClient, that's why I opted for the less intrusive global setting.

I don't see much use case for HttpClient users redefining user agents dynamically though, it's maybe the (rare) kind of thing that can be setup globally.

But then I also question my choice of putting the API in utils.h. I'll try moving it to http client itself.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No problem, I understand that we need to be practical and balance between an ideal but time consuming and a just enough but quicker solutions.
BTW, at first glance, this PR, IMHO, is related to this one #1273 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

lol - i've been watching this PR to see how things went before pushing my change which will at best produce a merge conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha well... This PR is not really urgent anyway. Would you also prefer that to be done another way?

Copy link
Collaborator

Choose a reason for hiding this comment

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

no. I was just wanted to see the approach that was chosen here since there's a good chance I could do the same thing in my change.

@lbonn
Copy link
Contributor Author

lbonn commented Aug 13, 2019

Should we go forward anyway?

Copy link
Collaborator

@pattivacek pattivacek left a comment

Choose a reason for hiding this comment

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

Should we go forward anyway?

Yeah, it seems fine to me.

@lbonn lbonn merged commit 17b03f0 into master Aug 13, 2019
@lbonn lbonn deleted the feat/OTA-3550/tools-user-agent branch August 13, 2019 12:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants