Skip to content

Commit

Permalink
Sdk v2.0.0 (#139)
Browse files Browse the repository at this point in the history
* Update Version information

* Missed the build

* Force Travis

* Force Travis

* Update CSR to Csr
  • Loading branch information
bretterer authored Jun 6, 2020
1 parent 7410b46 commit 0b49dc6
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 44 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
Running changelog of releases since `2.0.0-rc.4`

## v2.0.0
- Official Release of v2 Okta Golang SDK
- Official Release of v2 Okta Golang SDK (June 4, 2020)
- `CSR` Model has been renamed to `Csr`
- `CSRMetadata` Model has been renamed to `CsrMetadata`
- `CSRMetadataSubject` Model has been renamed to `CsrMetadataSubject`
- `CSRMetadataSubjectAltNames` Model has been renamed to `CsrMetadataSubjectAltNames`
- `GenerateCsrForIdentityProvider` now sets accept header correctly to `application/json`

## v2.0.0-rc.5
- Remove `PreviewSamlMetadataForApplication` method from `ApplicationResource`
Expand Down
16 changes: 8 additions & 8 deletions okta/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ func (m *ApplicationResource) CreateApplication(ctx context.Context, body App, q
return application, resp, nil
}

// Enumerates CSRs for an application
func (m *ApplicationResource) ListCsrsForApplication(ctx context.Context, appId string) ([]*CSR, *Response, error) {
// Enumerates Certificate Signing Requests for an application
func (m *ApplicationResource) ListCsrsForApplication(ctx context.Context, appId string) ([]*Csr, *Response, error) {
url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs", appId)

req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}

var csr []*CSR
var csr []*Csr

resp, err := m.client.requestExecutor.Do(ctx, req, &csr)
if err != nil {
Expand All @@ -185,15 +185,15 @@ func (m *ApplicationResource) ListCsrsForApplication(ctx context.Context, appId
}

// Generates a new key pair and returns the Certificate Signing Request for it.
func (m *ApplicationResource) GenerateCsrForApplication(ctx context.Context, appId string, body CSRMetadata) (*CSR, *Response, error) {
func (m *ApplicationResource) GenerateCsrForApplication(ctx context.Context, appId string, body CsrMetadata) (*Csr, *Response, error) {
url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs", appId)

req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body)
if err != nil {
return nil, nil, err
}

var csr *CSR
var csr *Csr

resp, err := m.client.requestExecutor.Do(ctx, req, &csr)
if err != nil {
Expand All @@ -203,7 +203,7 @@ func (m *ApplicationResource) GenerateCsrForApplication(ctx context.Context, app
return csr, resp, nil
}

func (m *ApplicationResource) RevokeCSRFromApplication(ctx context.Context, appId string, csrId string) (*Response, error) {
func (m *ApplicationResource) RevokeCsrFromApplication(ctx context.Context, appId string, csrId string) (*Response, error) {
url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v", appId, csrId)

req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("DELETE", url, nil)
Expand All @@ -219,15 +219,15 @@ func (m *ApplicationResource) RevokeCSRFromApplication(ctx context.Context, appI
return resp, nil
}

func (m *ApplicationResource) GetCsrForApplication(ctx context.Context, appId string, csrId string) (*CSR, *Response, error) {
func (m *ApplicationResource) GetCsrForApplication(ctx context.Context, appId string, csrId string) (*Csr, *Response, error) {
url := fmt.Sprintf("/api/v1/apps/%v/credentials/csrs/%v", appId, csrId)

req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}

var csr *CSR
var csr *Csr

resp, err := m.client.requestExecutor.Do(ctx, req, &csr)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion okta/csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"
)

type CSR struct {
type Csr struct {
Created *time.Time `json:"created,omitempty"`
Csr string `json:"csr,omitempty"`
Id string `json:"id,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions okta/csrMetadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package okta

import ()

type CSRMetadata struct {
Subject *CSRMetadataSubject `json:"subject,omitempty"`
SubjectAltNames *CSRMetadataSubjectAltNames `json:"subjectAltNames,omitempty"`
type CsrMetadata struct {
Subject *CsrMetadataSubject `json:"subject,omitempty"`
SubjectAltNames *CsrMetadataSubjectAltNames `json:"subjectAltNames,omitempty"`
}
2 changes: 1 addition & 1 deletion okta/csrMetadataSubject.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package okta

import ()

type CSRMetadataSubject struct {
type CsrMetadataSubject struct {
CommonName string `json:"commonName,omitempty"`
CountryName string `json:"countryName,omitempty"`
LocalityName string `json:"localityName,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion okta/csrMetadataSubjectAltNames.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ package okta

import ()

type CSRMetadataSubjectAltNames struct {
type CsrMetadataSubjectAltNames struct {
DnsNames []string `json:"dnsNames,omitempty"`
}
30 changes: 15 additions & 15 deletions okta/identityProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ func (m *IdentityProviderResource) GetIdentityProviderKey(ctx context.Context, k
return jsonWebKey, resp, nil
}

// Enumerates signing CSRs for an IdP
func (m *IdentityProviderResource) ListCsrsForIdentityProvider(ctx context.Context, idpId string) ([]*CSR, *Response, error) {
// Enumerates Certificate Signing Requests for an IdP
func (m *IdentityProviderResource) ListCsrsForIdentityProvider(ctx context.Context, idpId string) ([]*Csr, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs", idpId)

req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}

var csr []*CSR
var csr []*Csr

resp, err := m.client.requestExecutor.Do(ctx, req, &csr)
if err != nil {
Expand All @@ -233,15 +233,15 @@ func (m *IdentityProviderResource) ListCsrsForIdentityProvider(ctx context.Conte
}

// Generates a new key pair and returns a Certificate Signing Request for it.
func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(ctx context.Context, idpId string, body CSRMetadata) (*CSR, *Response, error) {
func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(ctx context.Context, idpId string, body CsrMetadata) (*Csr, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs", idpId)

req, err := m.client.requestExecutor.WithAccept("application/pkcs10").WithContentType("application/json").NewRequest("POST", url, body)
req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("POST", url, body)
if err != nil {
return nil, nil, err
}

var csr *CSR
var csr *Csr

resp, err := m.client.requestExecutor.Do(ctx, req, &csr)
if err != nil {
Expand All @@ -251,7 +251,7 @@ func (m *IdentityProviderResource) GenerateCsrForIdentityProvider(ctx context.Co
return csr, resp, nil
}

// Revoke a CSR and delete the key pair from the IdP
// Revoke a Certificate Signing Request and delete the key pair from the IdP
func (m *IdentityProviderResource) RevokeCsrForIdentityProvider(ctx context.Context, idpId string, csrId string) (*Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v", idpId, csrId)

Expand All @@ -268,16 +268,16 @@ func (m *IdentityProviderResource) RevokeCsrForIdentityProvider(ctx context.Cont
return resp, nil
}

// Gets a specific CSR model by id
func (m *IdentityProviderResource) GetCsrForIdentityProvider(ctx context.Context, idpId string, csrId string) (*CSR, *Response, error) {
// Gets a specific Certificate Signing Request model by id
func (m *IdentityProviderResource) GetCsrForIdentityProvider(ctx context.Context, idpId string, csrId string) (*Csr, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v", idpId, csrId)

req, err := m.client.requestExecutor.WithAccept("application/json").WithContentType("application/json").NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
}

var csr *CSR
var csr *Csr

resp, err := m.client.requestExecutor.Do(ctx, req, &csr)
if err != nil {
Expand All @@ -287,7 +287,7 @@ func (m *IdentityProviderResource) GetCsrForIdentityProvider(ctx context.Context
return csr, resp, nil
}

// Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP.
// Update the Certificate Signing Request with a signed X.509 certificate and add it into the signing key credentials for the IdP.
func (m *IdentityProviderResource) PublishCerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId)

Expand All @@ -306,7 +306,7 @@ func (m *IdentityProviderResource) PublishCerCertForIdentityProvider(ctx context
return jsonWebKey, resp, nil
}

// Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP.
// Update the Certificate Signing Request with a signed X.509 certificate and add it into the signing key credentials for the IdP.
func (m *IdentityProviderResource) PublishBinaryCerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId)

Expand All @@ -325,7 +325,7 @@ func (m *IdentityProviderResource) PublishBinaryCerCertForIdentityProvider(ctx c
return jsonWebKey, resp, nil
}

// Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP.
// Update the Certificate Signing Request with a signed X.509 certificate and add it into the signing key credentials for the IdP.
func (m *IdentityProviderResource) PublishDerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId)

Expand All @@ -344,7 +344,7 @@ func (m *IdentityProviderResource) PublishDerCertForIdentityProvider(ctx context
return jsonWebKey, resp, nil
}

// Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP.
// Update the Certificate Signing Request with a signed X.509 certificate and add it into the signing key credentials for the IdP.
func (m *IdentityProviderResource) PublishBinaryDerCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId)

Expand All @@ -363,7 +363,7 @@ func (m *IdentityProviderResource) PublishBinaryDerCertForIdentityProvider(ctx c
return jsonWebKey, resp, nil
}

// Update the CSR with a signed X.509 certificate and add it into the signing key credentials for the IdP.
// Update the Certificate Signing Request with a signed X.509 certificate and add it into the signing key credentials for the IdP.
func (m *IdentityProviderResource) PublishBinaryPemCertForIdentityProvider(ctx context.Context, idpId string, csrId string, body string) (*JsonWebKey, *Response, error) {
url := fmt.Sprintf("/api/v1/idps/%v/credentials/csrs/%v/lifecycle/publish", idpId, csrId)

Expand Down
2 changes: 1 addition & 1 deletion okta/okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/kelseyhightower/envconfig"
)

const Version = "2.0.0-rc.5"
const Version = "2.0.0"

type Client struct {
config *config
Expand Down
2 changes: 1 addition & 1 deletion openapi/generator/createdFiles.json

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions openapi/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ function lowercaseFirstLetter(text) {
function ucFirst(text) {
switch(text) {
case 'csr':
return 'CSR';
return 'Csr';
case 'csrMetadata':
return 'CSRMetadata';
return 'CsrMetadata';
case 'csrMetadataSubject':
return 'CSRMetadataSubject';
return 'CsrMetadataSubject';
case 'csrMetadataSubjectAltNames':
return 'CSRMetadataSubjectAllNames';
return 'CsrMetadataSubjectAllNames';
default:
return text.charAt(0).toUpperCase() + text.slice(1);
}
Expand Down Expand Up @@ -184,6 +184,11 @@ function getImports(object) {

imports = [...new Set(imports)];

if (object.model.modelName == "Role") {
imports.splice (imports.indexOf("context"), 1);
imports.splice (imports.indexOf("fmt"), 1);
}

return imports;
}

Expand Down Expand Up @@ -373,6 +378,22 @@ function buildModelProperties(model) {
return finalProps.join("\n\t");
}

function isInstance(model) {
if ( model.modelName == "Csr" ||
model.modelName == "CsrMetadata" ||
model.modelName == "CsrMetadataSubject" ||
model.modelName == "CsrMetadataSubjectAltNames" ||
model.modelName == "OAuth2Claim" ||
model.modelName == "OAuth2ScopeConsentGrant") {
return false
}

if ( model.tags[0] == "Application" || model.tags[0] == "UserFactor") {
return true
}
return false
}

function log(item) {
console.log(item);
}
Expand Down Expand Up @@ -491,7 +512,8 @@ golang.process = ({ spec, operations, models, handlebars }) => {
responseModelInterface,
applicationModelInterface,
factorModelInterface,
factorInstanceOperation
factorInstanceOperation,
isInstance
});

handlebars.registerPartial('partials.copyHeader', fs.readFileSync('generator/templates/partials/copyHeader.hbs', 'utf8'));
Expand Down
4 changes: 2 additions & 2 deletions openapi/generator/templates/model.go.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Factor interface {
}

{{/if}}
{{#if (or (or (gt model.methods.length 0) (gt model.crud.length 0)) (eq model.modelName "LogEvent"))}}
{{#if (and (or (or (gt model.methods.length 0) (gt model.crud.length 0)) (eq model.modelName "LogEvent")) (ne model.modelName "Role"))}}
type {{model.modelName}}Resource resource

{{/if}}
Expand All @@ -36,7 +36,7 @@ type {{model.modelName}} struct {
{{/if}}
{{#if model.enum}}
{{else}}
{{#if (or ( eq model.tags.[0] "Application" ) ( eq model.tags.[0] "UserFactor") ) }}
{{#if (isInstance model) }}
func New{{model.modelName}}() *{{model.modelName}} {
return &{{model.modelName}}{
{{#each model.properties as |prop|}}
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func Test_can_create_csr_for_application(t *testing.T) {

application := create_application(t)

subject := okta.CSRMetadataSubject{
subject := okta.CsrMetadataSubject{
CountryName: "US",
StateOrProvinceName: "California",
LocalityName: "San Francisco",
Expand All @@ -419,19 +419,19 @@ func Test_can_create_csr_for_application(t *testing.T) {
CommonName: "SP Issuer",
}

subjectAltNames := okta.CSRMetadataSubjectAltNames{
subjectAltNames := okta.CsrMetadataSubjectAltNames{
DnsNames: []string{"dev.okta.com"},
}

csr := okta.CSRMetadata{
csr := okta.CsrMetadata{
Subject: &subject,
SubjectAltNames: &subjectAltNames,
}

csrs, _, err := client.Application.GenerateCsrForApplication(ctx, application.Id, csr)
require.NoError(t, err, "Creating an application CSR should not error")
require.NoError(t, err, "Creating an application Csr should not error")

assert.IsType(t, &okta.CSR{}, csrs, "did not return a `okta.CSR` object")
assert.IsType(t, &okta.Csr{}, csrs, "did not return a `okta.Csr` object")

client.Application.DeactivateApplication(ctx, application.Id)
_, err = client.Application.DeleteApplication(ctx, application.Id)
Expand Down

0 comments on commit 0b49dc6

Please sign in to comment.