1 /*
2 * Copyright (C) 2016, Christian Halstrick <christian.halstrick@sap.com>
3 * Copyright (C) 2015, Sasa Zivkov <sasa.zivkov@sap.com>
4 * and other copyright owners as documented in the project's IP log.
5 *
6 * This program and the accompanying materials are made available
7 * under the terms of the Eclipse Distribution License v1.0 which
8 * accompanies this distribution, is reproduced below, and is
9 * available at http://www.eclipse.org/org/documents/edl-v10.php
10 *
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials provided
23 * with the distribution.
24 *
25 * - Neither the name of the Eclipse Foundation, Inc. nor the
26 * names of its contributors may be used to endorse or promote
27 * products derived from this software without specific prior
28 * written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
31 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
32 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
42 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44 package org.eclipse.jgit.lfs;
45
46 import java.util.List;
47 import java.util.Map;
48
49 import com.google.gson.FieldNamingPolicy;
50 import com.google.gson.Gson;
51 import com.google.gson.GsonBuilder;
52
53 /**
54 * This interface describes the network protocol used between lfs client and lfs
55 * server
56 *
57 * @since 4.11
58 */
59 public interface Protocol {
60 /** A request sent to an LFS server */
61 class Request {
62 /** The operation of this request */
63 public String operation;
64
65 /** The objects of this request */
66 public List<ObjectSpec> objects;
67 }
68
69 /** A response received from an LFS server */
70 class Response {
71 public List<ObjectInfo> objects;
72 }
73
74 /**
75 * MetaData of an LFS object. Needs to be specified when requesting objects
76 * from the LFS server and is also returned in the response
77 */
78 class ObjectSpec {
79 public String oid; // the objectid
80
81 public long size; // the size of the object
82 }
83
84 /**
85 * Describes in a response all actions the LFS server offers for a single
86 * object
87 */
88 class ObjectInfo extends ObjectSpec {
89 public Map<String, Action> actions; // Maps operation to action
90
91 public Error error;
92 }
93
94 /**
95 * Describes in a Response a single action the client can execute on a
96 * single object
97 */
98 class Action {
99 public String href;
100
101 public Map<String, String> header;
102 }
103
104 /**
105 * An action with an additional expiration timestamp
106 *
107 * @since 4.11
108 */
109 class ExpiringAction extends Action {
110 /**
111 * Absolute date/time in format "yyyy-MM-dd'T'HH:mm:ss.SSSX"
112 */
113 public String expiresAt;
114
115 /**
116 * Validity time in milliseconds (preferred over expiresAt as specified:
117 * https://github.com/git-lfs/git-lfs/blob/master/docs/api/authentication.md)
118 */
119 public String expiresIn;
120 }
121
122 /** Describes an error to be returned by the LFS batch API */
123 class Error {
124 public int code;
125
126 public String message;
127 }
128
129 /**
130 * The "download" operation
131 */
132 String OPERATION_DOWNLOAD = "download"; //$NON-NLS-1$
133
134 /**
135 * The "upload" operation
136 */
137 String OPERATION_UPLOAD = "upload"; //$NON-NLS-1$
138
139 /**
140 * The contenttype used in LFS requests
141 */
142 String CONTENTTYPE_VND_GIT_LFS_JSON = "application/vnd.git-lfs+json; charset=utf-8"; //$NON-NLS-1$
143
144 /**
145 * Authorization header when auto-discovering via SSH.
146 */
147 String HDR_AUTH = "Authorization"; //$NON-NLS-1$
148
149 /**
150 * Prefix of authentication token obtained through SSH.
151 */
152 String HDR_AUTH_SSH_PREFIX = "Ssh: "; //$NON-NLS-1$
153
154 /**
155 * Path to the LFS info servlet.
156 */
157 String INFO_LFS_ENDPOINT = "/info/lfs"; //$NON-NLS-1$
158
159 /**
160 * Path to the LFS objects servlet.
161 */
162 String OBJECTS_LFS_ENDPOINT = "/objects/batch"; //$NON-NLS-1$
163
164 /**
165 * @return a {@link Gson} instance suitable for handling this
166 * {@link Protocol}
167 *
168 * @since 4.11
169 */
170 public static Gson gson() {
171 return new GsonBuilder()
172 .setFieldNamingPolicy(
173 FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
174 .disableHtmlEscaping().create();
175 }
176 }