added deprecation warnings to file_storage
[arvados.git] / lib / google / api_client / auth / storages / redis_store.rb
1 # Copyright 2013 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 require 'json'
16
17 module Google
18   class APIClient
19     class RedisStore
20
21       attr_accessor :redis
22
23       ##
24       # Initializes the RedisStore object.
25       #
26       # @params [Object] Redis instance
27       def initialize(redis)
28         @redis= redis
29       end
30
31       ##
32       # Attempt to read in credentials from redis.
33       def load_credentials
34         credentials = redis.get redis_credentials_key
35         JSON.parse(credentials) if credentials
36       end
37
38       def redis_credentials_key
39         "google_api_credentials"
40       end
41
42       ##
43       # Write the credentials to redis.
44       #
45       # @params [Hash] credentials
46       def write_credentials(credentials_hash)
47         redis.set(redis_credentials_key, credentials_hash.to_json)
48       end
49     end
50   end
51 end