Emcee

Форк
0
/
DeploymentDestinationAuthenticationType.swift 
55 строк · 1.8 Кб
1
import Foundation
2
import PathLib
3

4
public enum DeploymentDestinationAuthenticationType: Codable, CustomStringConvertible, Equatable, Hashable {
5
    case password(String)
6
    
7
    /// Absolute (arbitrary) path to a local key file.
8
    case key(path: AbsolutePath)
9
    
10
    // Look up a key inside ~/.ssh/
11
    case keyInDefaultSshLocation(filename: String)
12
    
13
    public var description: String {
14
        switch self {
15
        case .password:
16
            return "password auth"
17
        case .key:
18
            return "authorization using a key file at absolute path"
19
        case .keyInDefaultSshLocation:
20
            return "authorization using key from ~/.ssh/"
21
        }
22
    }
23
    
24
    private enum CodingKeys: String, CodingKey {
25
        case password
26
        case keyPath
27
        case filename
28
    }
29
    
30
    public init(from decoder: Decoder) throws {
31
        let container = try decoder.container(keyedBy: CodingKeys.self)
32
        do {
33
            self = .password(try container.decode(String.self, forKey: .password))
34
        } catch {
35
            do {
36
                self = .key(path: try container.decode(AbsolutePath.self, forKey: .keyPath))
37
            } catch {
38
                self = .keyInDefaultSshLocation(filename: try container.decode(String.self, forKey: .filename))
39
            }
40
            
41
        }
42
    }
43
    
44
    public func encode(to encoder: Encoder) throws {
45
        var container = encoder.container(keyedBy: CodingKeys.self)
46
        switch self {
47
        case .password(let password):
48
            try container.encode(password, forKey: .password)
49
        case .key(let path):
50
            try container.encode(path, forKey: .keyPath)
51
        case .keyInDefaultSshLocation(let filename):
52
            try container.encode(filename, forKey: .filename)
53
        }
54
    }
55
}
56

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.