-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from hmrc/APIS-2888
APIS-2888
- Loading branch information
Showing
26 changed files
with
481 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2017 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import com.google.inject.AbstractModule | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import play.api.{Configuration, Environment} | ||
import uk.gov.hmrc.apisubscriptionfields.config.MicroserviceAuditConnector | ||
import uk.gov.hmrc.play.audit.http.connector.AuditConnector | ||
|
||
class Module(environment: Environment, configuration: Configuration) extends AbstractModule { | ||
|
||
override def configure = { | ||
bind(classOf[Config]).toInstance(ConfigFactory.load()) | ||
bind(classOf[AuditConnector]).toInstance(MicroserviceAuditConnector) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/uk/gov/hmrc/apisubscriptionfields/controller/DocumentationController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2017 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.apisubscriptionfields.controller | ||
|
||
import javax.inject.Inject | ||
|
||
import controllers.AssetsBuilder | ||
import play.api.http.HttpErrorHandler | ||
import play.api.mvc.Action | ||
import uk.gov.hmrc.apisubscriptionfields.config.AppContext | ||
import uk.gov.hmrc.apisubscriptionfields.model.APIAccess | ||
import uk.gov.hmrc.play.microservice.controller.BaseController | ||
import uk.gov.hmrc.apisubscriptionfields.views.txt | ||
|
||
class DocumentationController @Inject()(httpErrorHandler: HttpErrorHandler, appContext: AppContext) extends AssetsBuilder(httpErrorHandler) with BaseController { | ||
|
||
def definition = Action { | ||
if(appContext.publishApiDefinition) { | ||
Ok(txt.definition(appContext.apiContext, APIAccess.build(appContext.access))).withHeaders(CONTENT_TYPE -> JSON) | ||
} else NotFound | ||
} | ||
|
||
def raml(version: String, file: String) = Action { | ||
if(appContext.publishApiDefinition) { | ||
Ok(txt.application(appContext.apiContext)) | ||
} else NotFound | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/uk/gov/hmrc/apisubscriptionfields/model/APIDefinition.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2017 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.hmrc.apisubscriptionfields.model | ||
|
||
import play.api.Configuration | ||
import play.api.libs.json._ | ||
|
||
case class APIAccess(`type`: APIAccessType.Value, whitelistedApplicationIds: Option[Seq[String]]) | ||
|
||
object APIAccess { | ||
def build(config: Option[Configuration]): APIAccess = APIAccess( | ||
`type` = APIAccessType.PRIVATE, | ||
whitelistedApplicationIds = config.flatMap(_.getStringSeq(s"whitelistedApplicationIds")).orElse(Some(Seq.empty))) | ||
} | ||
|
||
object APIAccessType extends Enumeration { | ||
type APIAccessType = Value | ||
val PRIVATE, PUBLIC = Value | ||
} | ||
|
||
object EnumJson { | ||
|
||
def enumReads[E <: Enumeration](enum: E): Reads[E#Value] = new Reads[E#Value] { | ||
def reads(json: JsValue): JsResult[E#Value] = json match { | ||
case JsString(s) => { | ||
try { | ||
JsSuccess(enum.withName(s)) | ||
} catch { | ||
case _: NoSuchElementException => | ||
throw new InvalidEnumException(enum.getClass.getSimpleName, s) | ||
} | ||
} | ||
case _ => JsError("String value expected") | ||
} | ||
} | ||
|
||
implicit def enumWrites[E <: Enumeration]: Writes[E#Value] = new Writes[E#Value] { | ||
def writes(v: E#Value): JsValue = JsString(v.toString) | ||
} | ||
|
||
implicit def enumFormat[E <: Enumeration](enum: E): Format[E#Value] = { | ||
Format(enumReads(enum), enumWrites) | ||
} | ||
} | ||
|
||
class InvalidEnumException(className: String, input:String) extends RuntimeException(s"Enumeration expected of type: '$className', but it does not contain '$input'") | ||
|
||
object APIDefinition { | ||
implicit val apiAccessTypeJsonformat = EnumJson.enumFormat(APIAccessType) | ||
implicit val apiAccessJsonformat = Json.format[APIAccess] | ||
} |
58 changes: 58 additions & 0 deletions
58
app/uk/gov/hmrc/apisubscriptionfields/views/application.scala.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@(apiContext: String)#%RAML 1.0 | ||
--- | ||
|
||
title: API Subscription Fields | ||
version: 1.0 | ||
protocols: [ HTTPS ] | ||
baseUri: https://api.service.hmrc.gov.uk/ | ||
|
||
mediaType: [ application/json ] | ||
|
||
uses: | ||
sec: https://developer.service.hmrc.gov.uk/api-documentation/assets/common/modules/securitySchemes.raml | ||
headers: https://developer.service.hmrc.gov.uk/api-documentation/assets/common/modules/headers.raml | ||
annotations: https://developer.service.hmrc.gov.uk/api-documentation/assets/common/modules/annotations.raml | ||
types: https://developer.service.hmrc.gov.uk/api-documentation/assets/common/modules/types.raml | ||
|
||
/@apiContext: | ||
/definition: | ||
/context: | ||
/{apiContext}: | ||
uriParameters: | ||
apiContext: | ||
type: string | ||
/version: | ||
/{apiVersion}: | ||
uriParameters: | ||
apiVersion: | ||
type: string | ||
get: | ||
is: [headers.acceptHeader] | ||
securedBy: [ sec.x-application ] | ||
/field: | ||
/application: | ||
/{clientId}: | ||
uriParameters: | ||
clientId: | ||
type: string | ||
/context: | ||
/{apiContext}: | ||
uriParameters: | ||
apiContext: | ||
type: string | ||
/version: | ||
/{apiVersion}: | ||
uriParameters: | ||
apiVersion: | ||
type: string | ||
get: | ||
is: [headers.acceptHeader] | ||
securedBy: [ sec.x-application ] | ||
put: | ||
is: [headers.acceptHeader] | ||
securedBy: [ sec.x-application ] | ||
delete: | ||
is: [headers.acceptHeader] | ||
securedBy: [ sec.x-application ] | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
app/uk/gov/hmrc/apisubscriptionfields/views/definition.scala.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import uk.gov.hmrc.apisubscriptionfields.model.APIAccess | ||
@import uk.gov.hmrc.apisubscriptionfields.model.APIDefinition._ | ||
@import play.api.libs.json.Json | ||
@(apiContext: String, access: APIAccess) | ||
{ | ||
"scopes":[], | ||
"api": { | ||
"name": "API Subscription Fields", | ||
"description": "Internal API for use by the developer hub", | ||
"context": "@apiContext", | ||
"versions": [ | ||
{ | ||
"version": "1.0", | ||
"status": "PUBLISHED", | ||
"access": @Json.toJson(access) | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.