Skip to content

Commit

Permalink
Merge pull request #148 from projectsyn/fix/token-file
Browse files Browse the repository at this point in the history
Fix read token from file
  • Loading branch information
Simon Rüegg authored Jul 27, 2020
2 parents 2ef70ef + 59e7409 commit d0d91eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Please document all notable changes to this project in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v0.2.1]

### Fixed

* Read token from file ([#146])

## [v0.2.0]

### Added
Expand Down Expand Up @@ -98,6 +104,7 @@ Initial implementation
[v0.1.5]: https://github.com/projectsyn/commodore/releases/tag/v0.1.5
[v0.1.6]: https://github.com/projectsyn/commodore/releases/tag/v0.1.6
[v0.2.0]: https://github.com/projectsyn/commodore/releases/tag/v0.2.0
[v0.2.1]: https://github.com/projectsyn/commodore/releases/tag/v0.2.1
[#53]: https://github.com/projectsyn/commodore/pull/53
[#58]: https://github.com/projectsyn/commodore/pull/58
[#81]: https://github.com/projectsyn/commodore/pull/81
Expand All @@ -120,3 +127,4 @@ Initial implementation
[#140]: https://github.com/projectsyn/commodore/pull/140
[#143]: https://github.com/projectsyn/commodore/pull/143
[#145]: https://github.com/projectsyn/commodore/pull/145
[#146]: https://github.com/projectsyn/commodore/pull/146
24 changes: 14 additions & 10 deletions commodore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ class Config:
def __init__(self, api_url=None, api_token=None, global_git=None, verbose=False, username=None, usermail=None):
self.api_url = api_url
self.api_token = None
if api_token is not None:
try:
p = P(api_token)
if p.is_file():
with open(p) as apitoken:
api_token = apitoken.read()
except OSError:
# Assume token is not configured as file
pass
self.api_token = api_token.strip()
self.api_token = api_token
self.global_git_base = global_git
self._components = {}
self._config_repos = {}
Expand Down Expand Up @@ -59,6 +50,19 @@ def config_file(self):
def default_component_base(self):
return f"{self.global_git_base}/commodore-components"

@property
def api_token(self):
return self._api_token

@api_token.setter
def api_token(self, api_token):
if api_token is not None:
p = P(api_token)
if p.is_file():
with open(p) as apitoken:
api_token = apitoken.read()
self._api_token = api_token.strip()

def update_verbosity(self, verbose):
self._verbose += verbose

Expand Down

0 comments on commit d0d91eb

Please sign in to comment.