Skip to content

Instantly share code, notes, and snippets.

@letzya
Last active June 15, 2020 17:39
Show Gist options
  • Save letzya/2735492869532ab150f414b45376a137 to your computer and use it in GitHub Desktop.
Save letzya/2735492869532ab150f414b45376a137 to your computer and use it in GitHub Desktop.
Catalogue which doesn't display internal apis to external developers or non logged in viewers
{{ define "cataloguePage" }} {{ $org_id := .OrgId}} {{ template "header" .}}
{{ $page := .}}
<body>
{{ template "navigation" . }}
<div>
<!-- Main content here -->
<div class="container" style="margin-top:80px;">
<div class="row">
<h1>API Catalogue yaara</h1>
</div>
<div class="row">
{{ if .Data.APIS }}
{{if .Profile.Fields}}
{{$internal := index .Profile.Fields "internal"}}
{{printf "interna: %#v" $internal}}
{{ range $index, $apiDetail := .Data.APIS}}
{{ if $apiDetail.Show }}
{{if (and (eq $apiDetail.Name "Internal apis") (eq $internal "0") )}}
<p>Cant show this internal catalogue to external developer {{ printf "(catalogue name: %#v)" $apiDetail.Name }} </p>
{{else}}
<div class="col-md-4">
<h2>{{$apiDetail.Name}}</h2>
<p>{{$apiDetail.LongDescription | markDown}}</p>
{{ if $apiDetail.Documentation }}
<a href="{{ $page.PortalRoot }}apis/{{$apiDetail.Documentation}}/documentation/" class="btn btn-info catalogue">
<span class="glyphicon glyphicon-book" aria-hidden="true"></span>&nbsp; View documentation
</a>
<br/>
{{ end }}
{{if eq $apiDetail.Version "" }}
{{if eq $apiDetail.IsKeyless false}}
<a href="{{ $page.PortalRoot }}member/apis/{{$apiDetail.APIID}}/request" class="btn btn-success catalogue">
<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>&nbsp; Request an API key
</a>
{{ end }}
{{ else }}
{{if eq $apiDetail.IsKeyless false}}
<a href="{{ $page.PortalRoot }}member/policies/{{$apiDetail.PolicyID}}/request" class="btn btn-success catalogue">
<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>&nbsp; Request an API key
</a>
{{ end }}
{{ end }}
</div>
{{ end }}
{{ end }}
{{ end }}
{{ else }}
{{ range $index, $apiDetail := .Data.APIS}}
{{ if $apiDetail.Show }}
{{if (ne $apiDetail.Name "Internal apis") }}
<div class="col-md-4">
<h2>{{$apiDetail.Name}}</h2>
<p>{{$apiDetail.LongDescription | markDown}}</p>
{{ if $apiDetail.Documentation }}
<a href="{{ $page.PortalRoot }}apis/{{$apiDetail.Documentation}}/documentation/" class="btn btn-info catalogue">
<span class="glyphicon glyphicon-book" aria-hidden="true"></span>&nbsp; View documentation
</a>
<br/>
{{ end }}
{{if eq $apiDetail.Version "" }}
{{if eq $apiDetail.IsKeyless false}}
<a href="{{ $page.PortalRoot }}member/apis/{{$apiDetail.APIID}}/request" class="btn btn-success catalogue">
<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>&nbsp; Request an API key
</a>
{{ end }}
{{ else }}
{{if eq $apiDetail.IsKeyless false}}
<a href="{{ $page.PortalRoot }}member/policies/{{$apiDetail.PolicyID}}/request" class="btn btn-success catalogue">
<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>&nbsp; Request an API key
</a>
{{ end }}
{{ end }}
</div>
{{end}}
{{end}}
{{end}}
{{ end }}
{{ else }}
<div class="row">
<p>
<em>It looks like there are no APIs in the Catalogue.</em>
</p>
</div>
{{ end }}
</div>
</div>
{{ template "footer" .}}
</div>
<!-- /container -->
{{ template "scripts" .}}
</body>
</html>
{{ end }}
@seathan11
Copy link

seathan11 commented Jun 15, 2020

Hello Yaraa,

The .UserData object has replaced the .Profile object in the developer portal templates

The following lines

{{if .Profile.Fields}}
{{$internal := index .Profile.Fields "internal"}}

Should be replaced with

{{if .UserData.Fields}}
{{$internal := index .UserData.Fields "internal"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment