You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Protocol.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2016, Christian Halstrick <christian.halstrick@sap.com>
  3. * Copyright (C) 2015, Sasa Zivkov <sasa.zivkov@sap.com> and others
  4. *
  5. * This program and the accompanying materials are made available under the
  6. * terms of the Eclipse Distribution License v. 1.0 which is available at
  7. * https://www.eclipse.org/org/documents/edl-v10.php.
  8. *
  9. * SPDX-License-Identifier: BSD-3-Clause
  10. */
  11. package org.eclipse.jgit.lfs;
  12. import java.util.List;
  13. import java.util.Map;
  14. import com.google.gson.FieldNamingPolicy;
  15. import com.google.gson.Gson;
  16. import com.google.gson.GsonBuilder;
  17. /**
  18. * This interface describes the network protocol used between lfs client and lfs
  19. * server
  20. *
  21. * @since 4.11
  22. */
  23. public interface Protocol {
  24. /** A request sent to an LFS server */
  25. class Request {
  26. /** The operation of this request */
  27. public String operation;
  28. /** The objects of this request */
  29. public List<ObjectSpec> objects;
  30. }
  31. /** A response received from an LFS server */
  32. class Response {
  33. public List<ObjectInfo> objects;
  34. }
  35. /**
  36. * MetaData of an LFS object. Needs to be specified when requesting objects
  37. * from the LFS server and is also returned in the response
  38. */
  39. class ObjectSpec {
  40. public String oid; // the objectid
  41. public long size; // the size of the object
  42. }
  43. /**
  44. * Describes in a response all actions the LFS server offers for a single
  45. * object
  46. */
  47. class ObjectInfo extends ObjectSpec {
  48. public Map<String, Action> actions; // Maps operation to action
  49. public Error error;
  50. }
  51. /**
  52. * Describes in a Response a single action the client can execute on a
  53. * single object
  54. */
  55. class Action {
  56. public String href;
  57. public Map<String, String> header;
  58. }
  59. /**
  60. * An action with an additional expiration timestamp
  61. *
  62. * @since 4.11
  63. */
  64. class ExpiringAction extends Action {
  65. /**
  66. * Absolute date/time in format "yyyy-MM-dd'T'HH:mm:ss.SSSX"
  67. */
  68. public String expiresAt;
  69. /**
  70. * Validity time in milliseconds (preferred over expiresAt as specified:
  71. * https://github.com/git-lfs/git-lfs/blob/master/docs/api/authentication.md)
  72. */
  73. public String expiresIn;
  74. }
  75. /** Describes an error to be returned by the LFS batch API */
  76. class Error {
  77. public int code;
  78. public String message;
  79. }
  80. /**
  81. * The "download" operation
  82. */
  83. String OPERATION_DOWNLOAD = "download"; //$NON-NLS-1$
  84. /**
  85. * The "upload" operation
  86. */
  87. String OPERATION_UPLOAD = "upload"; //$NON-NLS-1$
  88. /**
  89. * The contenttype used in LFS requests
  90. */
  91. String CONTENTTYPE_VND_GIT_LFS_JSON = "application/vnd.git-lfs+json; charset=utf-8"; //$NON-NLS-1$
  92. /**
  93. * Authorization header when auto-discovering via SSH.
  94. */
  95. String HDR_AUTH = "Authorization"; //$NON-NLS-1$
  96. /**
  97. * Prefix of authentication token obtained through SSH.
  98. */
  99. String HDR_AUTH_SSH_PREFIX = "Ssh: "; //$NON-NLS-1$
  100. /**
  101. * Path to the LFS info servlet.
  102. */
  103. String INFO_LFS_ENDPOINT = "/info/lfs"; //$NON-NLS-1$
  104. /**
  105. * Path to the LFS objects servlet.
  106. */
  107. String OBJECTS_LFS_ENDPOINT = "/objects/batch"; //$NON-NLS-1$
  108. /**
  109. * @return a {@link Gson} instance suitable for handling this
  110. * {@link Protocol}
  111. *
  112. * @since 4.11
  113. */
  114. public static Gson gson() {
  115. return new GsonBuilder()
  116. .setFieldNamingPolicy(
  117. FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
  118. .disableHtmlEscaping().create();
  119. }
  120. }