Class: SafeDb::RemoteGithubToken
- Inherits:
-
EditVerse
- Object
- Controller
- EditVerse
- SafeDb::RemoteGithubToken
- Defined in:
- lib/controller/db/remote-github-token.rb
Overview
This class uses Github (https) along with an access token (as opposed to ssh keypairs) to provision a remote backend for a safe database.
Github Access Token
The safe book must be opened at a chapter/verse that contains a line named ‘@github.access.token` with a viable token value. This is the only pre-condition to the `safe remote –provision` command.
Flow of Events
To provision a Github token-based remote backend for the safe database means
-
a repository is created in github
-
the repository name and user are stored in the verse
-
the fetch/pull/clone url is put into configuration visible before login
-
the push origin url is added using the ‘git remote add origin` command
Finally prompt the user to issue a commit followed by a push.
Instance Attribute Summary collapse
-
#provision ⇒ Object
writeonly
Sets the attribute provision.
Instance Method Summary collapse
-
#edit_verse ⇒ Object
We want to provision (create) the safe’s remote (github) backend.
- #is_github_access_token_valid(github_access_token) ⇒ Object
Methods inherited from EditVerse
Methods inherited from Controller
#check_post_conditions, #check_pre_conditions, #execute, #flow, #initialize, #open_remote_backend_location, #post_validation, #pre_validation, #read_verse, #set_verse, #update_verse
Constructor Details
This class inherits a constructor from SafeDb::Controller
Instance Attribute Details
#provision=(value) ⇒ Object (writeonly)
Sets the attribute provision
26 27 28 |
# File 'lib/controller/db/remote-github-token.rb', line 26 def provision=(value) @provision = value end |
Instance Method Details
#edit_verse ⇒ Object
We want to provision (create) the safe’s remote (github) backend. A number of setup tasks are executed when you ask that the backend repository be created.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/controller/db/remote-github-token.rb', line 30 def edit_verse() return unless @provision github_access_token = @verse[ Indices::GITHUB_ACCESS_TOKEN ] return unless is_github_access_token_valid( github_access_token ) repository_name = "safe-#{TimeStamp.yyjjj_hhmm_sst()}" @verse.store( Indices::GIT_REPOSITORY_NAME_KEYNAME, repository_name ) # We could hardcode this to genesis:remote/github which will be # referenced only on the first ever safe pull --from=https://github.com/devops4me/safe-xxxx # This is required for setting the push origin url. remote_mirror_page = "#{@book.book_id()}/#{@book.get_open_chapter_name()}/#{@book.get_open_verse_name()}" Master.new().set_backend_coordinates( remote_mirror_page ) repository_user = Github.create_repo( github_access_token, repository_name ) @verse.store( Indices::GIT_REPOSITORY_USER_KEYNAME, repository_user ) fetch_url = "https://github.com/#{repository_user}/#{repository_name}.git" push_url = "https://#{repository_user}:#{github_access_token}@github.com/#{repository_user}/#{repository_name}.git" GitFlow.add_origin_url( Indices::MASTER_CRYPTS_FOLDER_PATH, fetch_url ) GitFlow.set_push_origin_url( Indices::MASTER_CRYPTS_FOLDER_PATH, push_url ) end |
#is_github_access_token_valid(github_access_token) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/controller/db/remote-github-token.rb', line 57 def is_github_access_token_valid( github_access_token ) is_invalid = github_access_token.nil?() || github_access_token.strip().length() < 7 puts "No valid github access token found." if is_invalid return !is_invalid end |