Skip to content

Commit a9a844a

Browse files
authored
LFS bugfixes and improvements (#10)
* GitHub's LFS is now supported/working with these changes * Headers for invoking actions are now respected * User agent is now included in all requests * Bearer token auth is now supported (OAuth2, PAT, etc.) * Credentials class to abstract away username/pw/token
1 parent 58fbb59 commit a9a844a

File tree

7 files changed

+226
-41
lines changed

7 files changed

+226
-41
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2022 Salesforce, Inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
#include "credentials.h"
9+
10+
Credentials::Credentials()
11+
: m_Type(Type::None)
12+
{
13+
}
14+
15+
Credentials::Credentials(const std::string& username, const std::string& password)
16+
: m_Type(Type::UserNameAndPass)
17+
, m_Username(username)
18+
, m_PasswordOrToken(password)
19+
{
20+
}
21+
22+
Credentials::Credentials(const std::string& token)
23+
: m_Type(Type::Token)
24+
, m_Username()
25+
, m_PasswordOrToken(token)
26+
{
27+
}
28+
29+
Credentials::Type Credentials::GetType() const
30+
{
31+
return m_Type;
32+
}
33+
34+
const std::string& Credentials::GetUsername() const
35+
{
36+
return m_Username;
37+
}
38+
39+
const std::string& Credentials::GetPassword() const
40+
{
41+
return m_PasswordOrToken;
42+
}
43+
44+
const std::string& Credentials::GetToken() const
45+
{
46+
return m_PasswordOrToken;
47+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2022 Salesforce, Inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
* For full license text, see the LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
#pragma once
8+
9+
#include <string>
10+
11+
class Credentials
12+
{
13+
public:
14+
enum class Type
15+
{
16+
None,
17+
UserNameAndPass,
18+
Token
19+
};
20+
21+
Credentials();
22+
Credentials(const std::string& username, const std::string& password);
23+
Credentials(const std::string& token);
24+
25+
Type GetType() const;
26+
27+
const std::string& GetUsername() const;
28+
const std::string& GetPassword() const;
29+
const std::string& GetToken() const;
30+
31+
private:
32+
Type m_Type = Type::None;
33+
34+
const std::string m_Username;
35+
const std::string m_PasswordOrToken;
36+
};

0 commit comments

Comments
 (0)